Multiple fonts on one Matplotlib label

I am trying to do something relatively simple:

I want to be able to increase the font of one letter (say, the LaTeX variable, say, up to 30) and save the other letters in the label of a particular font (say, 20).

Does anyone have a quick fix? It seems rather complicated to me. I tried using { } for each "item" in the label

 plt.plot(a,b,'g',linewidth=3.5, label = 'a') plt.plot(c,d,'r',linewidth=3.5, label = 'c') plt.legend(labelspacing = 1.0,loc=1,prop={'size':40}) plt.xlabel({'a',fontsize=50},{ 'N',fontsize = 20}) plt.ylabel('%',fontsize =30) 

Thanks!

+4
source share
2 answers

One solution is to use text () and make several calls, carefully selecting where each letter goes:

 import pylab as plt a=[0,1] b=[0,1] plt.plot(a,b,'g',linewidth=3.5, label = 'a') plt.rc('text', usetex=True) plt.legend(labelspacing = 1.0,loc=1,prop={'size':40}) plt.text(0.45,-0.08,'a',fontsize=50) plt.text(0.53,-0.08, 'N',fontsize = 20) 

This is not perfect. Another option is to go through LaTeX. See Another answer I'm going to post.

+1
source

Here is the solution with LaTeX. The machine on which I am installed does not have LaTeX installed, so I have not tested this carefully.

 plt.plot(a,b,'g',linewidth=3.5, label = 'a') plt.rc('text', usetex=True) plt.legend(labelspacing = 1.0,loc=1,prop={'size':40}) plt.xlabel(r'{\fontsize{50pt}{3em}\selectfont{}a}{\fontsize{20pt}{3em}\selectfont{}N') 

(note r before the line. This tells pylab to just send the line directly to LaTeX as a raw string, and not treat \ f and \ s as special characters)

You can get much more detailed information using LaTeX-sized commands (you can specify the actual font or use different versions of the \ large, \ Large, \ small \ tiny ... commands).

+3
source

Source: https://habr.com/ru/post/983270/


All Articles