Matplotlib custom calls windows font library

created at 07-13-2021 views: 4

fonts in windows

The file of the font library is in .tff format
The windows pc terminal basically reaches the various fonts we need
First you need to find out where it is:

C:\Windows\Fonts

find fonts

Take my most commonly used Aria font as an example, double click to enter
there will be the following files

Aria font

specify font

Then call the Arial regular file as an example, upload this .tff file to the server (I plot diagrams on the terminal)

from matplotlib.font_manager import FontProperties
font = FontProperties(fname='/home/wangnan/arial.ttf')
a=np.linspace(1,6)
plt.plot(a,a)
plt.tick_params(labelsize=18)
plt.xlabel('My Label', FontProperties=font,size=22)
plt.yticks(FontProperties=font, size = 16) #xy-axis scale numbers
plt.xticks(FontProperties=font, size = 16)

example

If you want to change the font of the colorbar scale, you can define another tick to cover it.

cb1=plt.colorbar(c1,ticks=np.arange(-30,35,10),cax=position)
cb1.set_label(r'$\mathrm{\Delta O_{3}\_CHEM\ by\ BVOCs\ (ppb)}$', FontProperties=font,size=18)
#This step is very important
cb1.ax.set_yticklabels(np.arange(-30,35,10),FontProperties=font,size=16) 

example2

created at:07-13-2021
edited at: 07-14-2021: