How do you change the size of figures drawn with matplotlib?

你如何改变用matplotlib绘制的图形的大小?


figure tells you the call signature:

figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')

So figure(figsize=(1,1)) creates an inch-by-inch image, which will be 80-by-80 pixels unless you also give a different dpi argument.


If you've already got the figure created you can quickly do this:

fig = matplotlib.pyplot.gcf()
fig.set_size_inches(18.5, 10.5)
fig.savefig('test2png.png', dpi=100)

To propagate the size change to an existing gui window add forward=True

fig.set_size_inches(18.5, 10.5, forward=True)

Deprecation note:
As per the official Matplotlib guide, usage of the pylab module is no longer recommended. Please consider using the matplotlib.pyplot module instead, as described by this other answer.

The following seems to work:

from pylab import rcParams
rcParams['figure.figsize'] = 5, 10

This makes the figure's width 5 inches, and its height 10 inches.

The Figure class then uses this as the default value for one of its arguments.

链接地址: http://www.djcxy.com/p/64178.html

上一篇: 如何访问与D3 SVG对象相关的DOM元素?

下一篇: 你如何改变用matplotlib绘制的图形的大小?