我不断为在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)