7

I would like to have multiple title in my graph. A picture is better than anyword : enter image description here

I use a title for every graph (D2/E, D3/E and D4/E) and a suptitle for title 1 and 2 but they have the same font size. Is there a solution to have different size for Title 1 and Title 2 ?

I've already seen this solution using LaTeX but the thing is when I use plt.rc('text', usetex=True) every font and text are changed. Moreover, I use variable in each title and it looks like I can't do it with LaTeX.

Latika Agarwal
  • 973
  • 1
  • 6
  • 11
Yohann L.
  • 1,262
  • 13
  • 27

1 Answers1

13

You can use matplotlib.pyplot.text objects in order to achieve the same result. Note that you need to make sure you use the figure coordinate system by using the transform=fig.transFigure argument and set the horizontal alignment using ha = "center"

An example:

import matplotlib.pyplot as plt

fig, axes = plt.subplots(1,3)
plt.text(x=0.5, y=0.94, s="My title 1", fontsize=18, ha="center", transform=fig.transFigure)
plt.text(x=0.5, y=0.88, s= "My title 2 in different size", fontsize=12, ha="center", transform=fig.transFigure)

for i, ax in enumerate(axes.flatten()):
    ax.set_title("D{}/E".format(i))

plt.subplots_adjust(top=0.8, wspace=0.3)

plt.show()

enter image description here

DavidG
  • 24,279
  • 14
  • 89
  • 82
  • I tried this solution but without using 'transform=fig.transFigure', it wasn't working well, thanks a lot! – Yohann L. May 22 '18 at 09:11