我必须绘制一个向量图,我只想看到没有轴、标题等的向量,所以下面是我尝试的方法:
pyplot.figure(None, figsize=(10, 16), dpi=100)
pyplot.quiver(data['x'], data['y'], data['u'], data['v'],
pivot='tail',
units='dots',
scale=0.2,
color='black')
pyplot.autoscale(tight=True)
pyplot.axis('off')
ax = pyplot.gca()
ax.xaxis.set_major_locator(pylab.NullLocator())
ax.yaxis.set_major_locator(pylab.NullLocator())
pyplot.savefig("test.png",
bbox_inches='tight',
transparent=True,
pad_inches=0)尽管我努力到1600年有一个1000的图像,但到1280年我得到了一张775张。怎样才能使它达到所需的尺寸?谢谢。
更新所提供的解决方案可以工作,但在我的情况下,我还必须手动设置轴限值。否则,matplotlib就无法计算出“紧”边框。
发布于 2012-10-22 19:54:38
import matplotlib.pyplot as plt
import numpy as np
sin, cos = np.sin, np.cos
fig = plt.figure(frameon = False)
fig.set_size_inches(5, 8)
ax = plt.Axes(fig, [0., 0., 1., 1.], )
ax.set_axis_off()
fig.add_axes(ax)
x = np.linspace(-4, 4, 20)
y = np.linspace(-4, 4, 20)
X, Y = np.meshgrid(x, y)
deg = np.arctan(Y**3-3*Y-X)
plt.quiver(X, Y, cos(deg), sin(deg), pivot='tail', units='dots', color='red')
plt.savefig('/tmp/test.png', dpi=200)收益率

通过将图形设置为5x8英寸,可以生成图像1000x1600像素。
fig.set_size_inches(5, 8)并使用DPI=200进行保存
plt.savefig('/tmp/test.png', dpi=200)删除边框的代码是从here中提取的。
(由于1000x1600是相当大的,所以上面发布的图像是不适合缩放的)。
https://stackoverflow.com/questions/13018115
复制相似问题