【发布时间】:2016-06-07 13:10:21
【问题描述】:
我已阅读有关此主题的所有 stackoverflow 问题,但均未成功。 上面的代码是我可以得到的最接近没有轴和边框的图像的东西。 我无法控制图像分辨率,因为我在 gimp 中打开图像时的 dpi 与我选择的不同。 我想要一个 7158 x 16392 和 72 dpi 的最终图像,没有任何边框或框架。
from stl import mesh
from matplotlib import collections
from matplotlib import pyplot
figure, axes = pyplot.subplots(frameon=False)
figure.set_size_inches(99.5,228)
# Read the STL file
your_mesh = mesh.Mesh.from_file('2d_35MeshTest.STL')
axes.set_xlim(your_mesh.min_[0], your_mesh.max_[0])
axes.set_ylim(your_mesh.min_[1], your_mesh.max_[1])
axes.add_collection(collections.PolyCollection(your_mesh.vectors[:, :, :2], linewidth=1,
facecolors=(1,1,1),alpha=1, edgecolors=(1,0,0) ))
print your_mesh.vectors.shape
pyplot.gca().set_aspect('equal')
pyplot.axis('off')
ax = pyplot.Axes(figure, [0., 0., 1., 1.], )
figure.set_dpi(72)
figure.subplots_adjust(bottom = 0)
figure.subplots_adjust(top = 1)
figure.subplots_adjust(right = 1)
figure.subplots_adjust(left = 0)
figure.savefig('image_refined8.png', format='png', transparent=True, bbox_inches='tight', pad_inches = 0.001)
stl文件在这里stl file 图片输出为image output
【问题讨论】:
-
我误解了你的主要意图。只要图形为 7158 x 16392 像素,则不存在 dpi 问题。如果您希望发生这种情况,则不应使用 bbox_inches='tight',因为这会调整图形的大小。关闭轴后,您还将添加轴。顺便说一句,图像对我来说完全是白色的,除了轴和透明边框(可能是 pad_inches)。我似乎也无法运行您的代码。
stl来自哪里? -
我已经更新了代码和文件。当我使用“紧身”时,它不合适。
标签: python matplotlib collections