我正在使用from matplotlib.backends.backend_pdf import PdfPages生成包含多个(子)图的PDF。
有没有办法控制生成的pdf的方向(水平/垂直)?我经常收到水平PDF
谢谢
发布于 2015-08-23 19:19:34
如果您使用set_size_inches函数设置图形的大小,则PDF应自动为您想要的形状:
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
with PdfPages('portrait.pdf') as pdf:
x = range(10)
y = [y * 2 for y in x]
plt.figure()
plt.clf()
plt.plot(x, y)
plt.xlabel('x axis')
plt.ylabel('y axis')
figure = plt.gcf()
figure.set_size_inches([7,10])
pdf.savefig(figure)如果将大小更改为[10,7],应该会看到方向自动切换。
savefig确实有一个方向设置,例如orientation='portrait',但我认为这不会有任何影响。你可以试一试。
发布于 2018-03-29 00:27:54
下面的方法对我很有效:
with PdfPages('portrait.pdf') as pdf:
pdf.savefig(fig, orientation='portrait')
plt.close()https://stackoverflow.com/questions/32163714
复制相似问题