Bold Text Label in Python Plot

Here, we are going to learn how to make text and labels bold in matplotlib figures (Python plots)?
Submitted by Anuj Singh, on July 23, 2020

The command fontweight='bold' can be used to make a textbox or label in figure bold. The following example illustrates all four possible examples.

plt.text(4, -0.8, 'Bold Text', fontsize=14.0, fontweight='bold')
#Making Bold Text Box
Bold Text Label in Python Plot (1)
plt.title('Title', fontweight='bold')
#Making text bold in title of the figure
Bold Text Label in Python Plot (2)
plt.xlabel('x-Axis', fontweight='bold')
#Making text bold in x axis label of the figure
Bold Text Label in Python Plot (3)
plt.ylabel('Variation', fontweight='bold')
#Making text bold in y axis label of the figure
Bold Text Label in Python Plot (4)

Python code for bold text label

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0.1, 5, 0.1)
y = np.tan(x)*np.exp(-x)

#Lowercase Delta
#In text
plt.figure()
plt.plot(x,y, '.-', color='purple')
plt.title('Example')
plt.text(4, -0.8, 'Bold Text', fontsize=14.0, fontweight='bold')
plt.grid()
plt.show()

#In title
plt.figure()
plt.plot(x,y, '.-', color='purple')
plt.title('Title', fontweight='bold')
plt.grid()
plt.show()

#In x-axis label
plt.figure()
plt.plot(x,y, '.-', color='purple')
plt.xlabel('x-Axis', fontweight='bold')
plt.grid()
plt.show()

#In y-axis label
plt.figure()
plt.plot(x,y, '.-', color='purple')
plt.ylabel('Variation', fontweight='bold')
plt.grid()
plt.show()

Output:

Output is as figure





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.