Multiple size font in suptitle

ぃ、小莉子 提交于 2021-02-10 07:07:45

问题


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

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.


回答1:


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



来源:https://stackoverflow.com/questions/50463113/multiple-size-font-in-suptitle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!