matplotlib限制图保存PdfPages的大小

时间:2015-02-11 21:57:59

标签: python pdf numpy matplotlib ipython-notebook

包含的代码大约需要2分钟才能运行,并创建一个22 MB的pdf。有没有办法将每个保存的数字的大小限制在合理的限度(即1 mb)?

我已经检查了fig.get_dpi(),它报告了80,对于一个4“x 6”的数字应该是合理的大小。

%matplotlib inline
import numpy as np
from numpy.random import randn
from matplotlib.backends.backend_pdf import PdfPages

# This will be the basic way for me to save figures
pp = PdfPages('test.pdf')

# Simulate and plot random data
dr = 1
rMax = 300
rRange = np.arange(0, rMax, dr)
R, Z = np.meshgrid(rRange, rRange)
Y = randn(R.shape[0], R.shape[1])
fig, ax = subplots()
ax.pcolor(R, Z, Y, cmap='RdBu')

# Save figure and produce pdf
pp.savefig(fig)
pp.close()

0 个答案:

没有答案