使用 matplotlib,如何打印“实际尺寸"? [英] Using matplotlib, how can I print something "actual size"?

查看:41
本文介绍了使用 matplotlib,如何打印“实际尺寸"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多图,其中 x 轴和 y 轴以厘米为单位,并且我已经在使用 axis('equal') 来确保正确的纵横比.我想打印出这些图,以便当我测量轴内的距离时,这些距离对应于真实世界的厘米.

I have a number of plots where the x- and y-axes are in centimeter units, and I am already using axis('equal') to ensure proper aspect ratios. I would like to print out those plots so that when I measure distances within my axes, the distances correspond to real-world centimeters.

也就是说,绘图中 3 个单位 (cm) 长的线应打印为 3 cm 长.(一个更复杂的例子是在 Matplotlib 中绘制一个标尺,然后将其打印出来以使用/as/a标尺.)我在 matlab 和 mathematica 中找到了解决方案,但不适用于 Matplotlib.有没有一个神奇的公式来实现这一目标?我相信它需要一个特殊的组合/排序:figure(figsize=??), axis('equal'), fig.canvas.draw(),fig.savefig('filename',format="??"),可能是一些带有 fig.bbox 参数的数学,可能还有一个或多个 dpi 设置.我尝试了很多组合,但没有找到正确的组合.也许有一种更简单的方法......

That is, a line that is 3 units (cm) long in the plot should print out to be 3 cm long. (A more complex example would be drawing a ruler in Matplotlib, and then printing it out for use /as/ a ruler.) I found solutions in matlab and mathematica, but not for Matplotlib. Is there a magic formula to achieve this? I believe it will require a special combination/ordering of: figure(figsize=??), axis('equal'), fig.canvas.draw(), fig.savefig('filename',format="??"), possibly some math with fig.bbox parameters, and perhaps one or more dpi-settings. I have tried many combinations but haven't hit on the right one. And maybe there is a way-easier approach ...

推荐答案

将此添加到@pablo reyes 的回答中,检查打印机是否处于 100%,并且非常接近;

Add this to @pablo reyes' answer, check that the printer is at 100%, and it's pretty close;

ax.set_ylim(0,7)
ax.set_xlim(0,10)

ax.plot([0.5, 1.5],[0.25, 0.25],label='One cm?')
ax.plot([6,6],[1,2], label='One cm?')
ax.legend()

我们强制轴为我们知道的大小,我们使其数据转换匹配现实世界,我们可以打印尺子".

we force the axis to be a size we know, we make its data-transform match the real world, and we can "print a ruler".

这篇关于使用 matplotlib,如何打印“实际尺寸"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆