HomeLinuxMatplotlib Daring Textual content

Matplotlib Daring Textual content


Daring textual content is a strong software in information visualization that may assist emphasize vital data and make it stand out in a plot. “Matplotlib” offers a number of parameters that can be utilized to switch the type of textual content, equivalent to fontfamily, fontsize, fontstyle, fontweight, colour, and so on.

This submit offers numerous methods to daring a textual content in Matplotlib utilizing quite a few examples.

Create Daring Textual content in Matplotlib?

The “Matplotlib” module offers a number of methods to create daring textual content within the plots, relying on the choice and particular use case. The next are the widespread strategies:

Technique 1: Daring Textual content in Matplotlib Utilizing the “fontweight” Parameter

The “fontweight” parameter is used to set the burden of the actual font. A number of the font-weight values are regular, daring, gentle, heavy, ultrabold, and so on. This parameter is used within the under code to the daring textual content of the matplotlib graph:

import matplotlib.pyplot as plt
Identify = [‘Joseph’, ‘ALex’, ‘Henry’, ‘Anna’, ‘John’]
Age = [25, 42, 52, 29, 27]
plt.bar(Identify, Age)
plt.title(‘Instance Title’, fontweight=‘daring’)
plt.xlabel(‘X Label’, fontweight=700)
plt.ylabel(‘Y Label’, fontweight=‘daring’)
plt.present()

 

Within the above code:

  • Firstly, the “pyplot” module is imported as plt at first of this system.
  • The “bar()” operate is used to create the bar chart of the given specified information.
  • The “fontweight” parameter is used with the “plt.title()”, “plt.xlabel()” and “plt.ylabel()” features, respectively to daring the title and labeling of the bar graph.

Output

On this end result, the title textual content, xlabel, and ylabel textual content have change into daring through the mentioned parameter.

Technique 2: Daring Textual content in Matplotlib Utilizing the “weight” Parameter

The “weight” parameter in Matplotlib is a substitute for the fontweight parameter, and it may also be used to daring the textual content. Right here is an instance:

import matplotlib.pyplot as plt
Identify = [‘Joseph’, ‘ALex’, ‘Henry’, ‘Anna’, ‘John’]
Age = [25, 42, 52, 29, 27]
plt.bar(Identify, Age)
plt.title(‘Instance Title’, weight=‘daring’)
plt.xlabel(‘X Label’, weight=700)
plt.ylabel(‘Y Label’, weight=‘daring’)
plt.textual content(‘Joseph’, 45, ‘Daring Font’, fontsize=16, weight=‘daring’, colour= ‘crimson’)
plt.present()

 

Within the above code, recall the mentioned approaches to create the bar chart. After that, embody the “weight” parameter that accepts the identical values because the fontweight parameter, equivalent to ‘daring’, 700 to point the specified textual content weight.

Output

As analyzed, the title textual content, annotated textual content, xlabel, and ylabel textual content have change into daring through the “weight” parameter.

Conclusion

The “fontweight” and “weight” parameters are used to daring a textual content in Matplotlib. Bolding a textual content emphasizes key data and enhances visualizations. The fontweight and weight parameters settle for the desired string and numerical values equivalent to ‘daring’, 700, or daring, to point the specified textual content weight. This Python submit offered an in-depth information on how you can daring a textual content in Matplotlib utilizing quite a few examples.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments