pythonmatplotlib

Giving graphs a subtitle


I want to give my graph a title in big 18pt font, then a subtitle below it in smaller 10pt font. How can I do this in matplotlib? It appears the title() function only takes one single string with a single fontsize attribute. There has to be a way to do this, but how?


Solution

  • I don't think there is anything built-in, but you can do it by leaving more space above your axes and using figtext:

    axes([.1,.1,.8,.7])
    figtext(.5,.9,'Foo Bar', fontsize=18, ha='center')
    figtext(.5,.85,'Lorem ipsum dolor sit amet, consectetur adipiscing elit',fontsize=10,ha='center')
    

    ha is short for horizontalalignment.