Python Matplotlib multiple font sizes in one label

I draw in the IPython IDE using Matplotlib.pyplot and added the title using:

 plt.title('Mean WRFv3.5 LHF\n(September 16 - October 30, 2012)',fontsize=40) 

However, I want the first line to be 40 in size and the second line to be 18. Is this possible in matplotlib ? I have seen using \tiny and \Huge latex, but would like more control.

Thanks Aaron

+6
source share
2 answers

Try:

 import matplotlib.pyplot as plt plt.rc('text', usetex=True) plt.title(r'{\fontsize{30pt}{3em}\selectfont{}{Mean WRFv3.5 LHF\r}{\fontsize{18pt}{3em}\selectfont{}(September 16 - October 30, 2012)}') plt.show() 

A separate label with text in two different sizes.

That \r may want to be \n on your system.

I used Joel to answer your question.

+2
source

Not sure if this is what you want, but you can add suptitle or text and set the following for different fonts:

 plt.title('Mean WRFv3.5 LHF\n', fontsize=40) plt.suptitle('(September 16 - October 30, 2012)\n', fontsize=18) plt.text(0.5, 1, 'the third line', fontsize=13, ha='center') 

enter image description here

Hope this helps.

+1
source

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


All Articles