Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple font sizes in plot title

I'm plotting in an IPython IDE using Matplotlib.pyplot and added a title with:

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

However, I want the first line to be size 40 and the second line to be size 18. Is that possible in matplotlib? I saw the LaTeX use of \tiny and \Huge, but would like more control.

like image 421
Aaron Rosenberg Avatar asked Mar 03 '15 15:03

Aaron Rosenberg


People also ask

How big should the font be for a title?

Do not use hyphenations for the end of a line. Center the title. Only the first letter in the title is capitalized, except for proper names, elements and abbreviations. The title should be in 18 pt., bold font.

How do I change the font size on a plot in Matplotlib?

Plot x data points using plot() method. To change the font size of the scale in matplotlib, we can use labelsize in the ticks_params()method. To display the figure, use show() method.


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()

Single label with text of two different sizes.

That \r might want to be a \n on your system.

I used Joel's answer to address your question.

like image 85
marisano Avatar answered Sep 24 '22 11:09

marisano


Not sure if this is what you want, but you may add a suptitle or text and set at different fontsize like this:

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.

like image 33
Anzel Avatar answered Sep 24 '22 11:09

Anzel