字幕中的多种尺寸字体 [英] Multiple size font in suptitle
问题描述
我想在图表中有多个标题.图片胜于任何词:
我为每个图(D2/E、D3/E 和 D4/E)使用 title
并为标题 1 和 2 使用 suptitle
但它们具有相同的字体大小.有没有办法让标题 1 和标题 2 的大小不同?
我已经看过
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.
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()
这篇关于字幕中的多种尺寸字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!