我无法理解为什么我的文字标题没有出现在我的绘图上。我发现文档对于图例和标题标签的放置顺序非常令人困惑。
我的代码在这里,我不知道哪里出了问题。一切都按照我的预期出现(标题、轴标签、日期格式...),除了标题文本根本不存在。
fig = plt.figure(figsize=(24, 12), dpi=60)
ax = fig.add_subplot(111)
plt.plot(datetime_series,ws_cumsum_mean1,label='1979-1994')
plt.plot(datetime_series,ws_cumsum_mean2,label='1996-2005')
plt.plot(datetime_series,ws_cumsum_mean3,label='2006-2014')
txt = '''Caption text'''
plt.legend(loc='best')
这是我尝试添加标题的地方:
ax.text(0.5,-0.5,txt,transform=ax.transAxes)
.
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d-%m'))
plt.ylabel('Y label title')
plt.xlabel('X label title')
plt.title('Plot title')
Using
ax.text(0.5,-0.5,txt,transform=ax.transAxes)
you are placing the text at position (0.5,-0.5)
in axes coordinates. Axes coordinates range from (0,0)
(lower left corner) to (1,1)
upper right corner. (0.5,-0.5)
is thus outside the axes and in this case also outside the figure.
您可以尝试使用 0 到 -0.1 之间的一些数字作为 y 坐标,看看什么适合您的需要。或者使用图形坐标而不是轴坐标并将文本放置在 y=0 处,ax.text(0.5,0,txt,transform=fig.transFigure)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)