【发布时间】:2012-10-12 15:46:34
【问题描述】:
我必须制作一个矢量图,我只想看到没有轴、标题等的向量,所以我尝试这样做:
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)
尽管我努力制作 1000 x 1600 的图像,但我还是得到了一个 775 x 1280 的图像。如何使其达到所需的尺寸? 谢谢。
更新 提出的解决方案有效,但在我的情况下,我还必须手动设置轴限制。否则,matplotlib 无法找出“紧密”的边界框。
【问题讨论】:
-
使用 MPL,您必须保持两个 DPI 值。您在创建
figure对象时指定的对象是用于在屏幕上交互式显示图形。调用savefig时指定的另一个DPI 值适用于保存的文件(以任何格式)。这就是@unutbu 发布的解决方案有效的原因。
标签: python matplotlib