您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Matplotlib savefig图像修剪

Matplotlib savefig图像修剪

我不断为在matplotlib中执行相同操作的方法感到惊讶。 因此,我确信有人可以使此代码更简洁。 无论如何,这应该清楚地说明如何解决您的问题。

>>> import pylab
>>> fig = pylab.figure()

>>> pylab.axis('off')
(0.0, 1.0, 0.0, 1.0)
>>> pylab.plot([1,3,1,2,3])
[<matplotlib.lines.Line2D object at 0x37d8cd0>]
>>> pylab.plot([3,1,1,2,1])
[<matplotlib.lines.Line2D object at 0x37d8d10>]

>>> fig.get_size_inches()    # check default size (width, height)
array([ 8.,  6.])
>>> fig.set_size_inches(4,3) 
>>> fig.get_dpi()            # check default dpi (in inches)
80
>>> fig.set_dpi(40)

# using b@R_766_2419@_inches='tight' and pad_inches=0 
# I managed to remove most of the padding; 
# but a small amount still persists
>>> fig.savefig('out.svg', transparent=True, b@R_766_2419@_inches='tight', pad_inches=0)

文档savefig()

其他 2022/1/1 18:32:43 有431人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶