我对这个问题使用了一个肮脏的“修复”。我只是简单地生产两次。一旦我删除了所有的框架,标题等,并保存为PNG,在另一种情况下,我删除了实际数据,并将所需的所有组件作为矢量数据保存在PDF中。然后,我使用ImageMagick将png转换为包含位图数据的pdf,并使用pdftk覆盖来自pdf的矢量数据。这是matplotlib页面中的一个pcolor示例,采用我刚刚描述的方式进行调整。
import matplotlib.pyplot as plt
import numpy as np
import os
for case in ['frame','data']:
# make these smaller to increase the resolution
dx, dy = 0.02, 0.02
# generate 2 2d grids for the x & y bounds
y, x = np.mgrid[slice(-3, 3 + dy, dy),
slice(-3, 3 + dx, dx)]
z = (1 - x/2. + x ** 5 + y ** 3) * np.exp(-x ** 2 - y ** 2)
# x and y are bounds, so z should be the value *inside* those bounds.
# Therefore, remove the last value from the z array.
z = z[:-1, :-1]
z_min, z_max = -np.abs(z).max(), np.abs(z).max()
fig=plt.figure()
ax=fig.add_subplot(1,1,1)
im=plt.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max)
plt.title('pcolor')
# set the limits of the plot to the limits of the data
plt.axis([x.min(), x.max(), y.min(), y.max()])
if case is 'frame':
im.remove()
plt.savefig("frame.pdf",transparent=True)
if case is 'data':
ax.axison=False
plt.title('')
plt.savefig("data.png",transparent=True)
os.system('convert data.png data.pdf')
os.system('pdftk frame.pdf background data.pdf output final_plot.pdf')
os.system('rm data.png data.pdf frame.pdf')
基本上它是你已经在做的事情只是一个自动化的版本...
通过最近的(持续?)matplotlib调查的详细评论阅读,另一人作出这一同样的请求。 https://docs.google.com/spreadsheet/ccc?key=0AjrPjlTMRTwTdHpQS25pcTZIRWdqX0pNckNSU01sMHc&usp=sharing – esmit