gpt4 book ai didi

python - Matplotlib |将方向更改为纵向

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:05 24 4
gpt4 key购买 nike

我有这个脚本可以在同一页上绘制 7 个系列。我想将页面方向设置为纵向。正如您在下面看到的,我已经尝试过:

f.savefig(sta+'.pdf', orientation='portrait', format='pdf')

但是没有任何反应!

你有什么建议吗?

f, (ax1, ax2, ax3, ax4, ax5, ax6, ax7) = plt.subplots(7, sharex=True, sharey=False)
plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=0.5)
ax1.plot(xtr[:num.size(xt),i], color='black')
ax2.plot(ytr[:num.size(yt),i], color='black')
ax3.plot(ztr[:num.size(zt),i], color='black')
ax4.plot(obs_dataV[:,i], color='g')
ax5.plot(obs_dataH[:,i], color='r')
ax6.plot(obs_dataP, color='g')
ax7.plot(obs_dataS, color='r')
ax1.set_title( sta+' Raw data', loc='left', fontsize='10')
ax4.set_title('Vertical and Horizontal traces', loc='left', fontsize='10')
ax6.set_title('Characteristic functions', loc='left', fontsize='10')
ax1.legend('X',loc='center right', fontsize='12')
ax2.legend('Y',loc='upper right', fontsize='12')
ax3.legend('Z',loc='upper right', fontsize='12')
ax4.legend('P',loc='upper right', fontsize='12')
ax5.legend('S',loc='upper right', fontsize='12')
ax6.legend('P',loc='upper right', fontsize='12')
ax7.legend('S',loc='upper right', fontsize='12')
f.savefig(sta+'.pdf', orientation='portrait', format='pdf')
plt.show()

提前致谢:-)

最佳答案

我认为您想要更改图形大小,而不是与页面布局有关的任何内容。 orientation kwarg to savefig 实际上只适用于 PS 和 EPS 后端。对于 PDF,页面大小定义为等于图形大小,因此它没有任何影响。

作为您当前结果的快速示例:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=7, sharex=True, sharey=False)
fig.subplots_adjust(hspace=0.5)
plt.show()

enter image description here

要改变图形的大小,使用figsize kwarg:

import matplotlib.pyplot as plt
fig, ax = plt.subplots(nrows=7, figsize=(8, 11), sharex=True, sharey=False)
fig.subplots_adjust(hspace=0.5)
plt.show()

enter image description here

关于python - Matplotlib |将方向更改为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27131643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com