How do you change the size of figure drawn with matplotlib?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
figure tells you the call signature:
figure(figsize=(1,1))
would create an inch-by-inch image, which would be 80-by-80 pixels unless you also give a different dpi argument.This resizes the figure immediately even after the figure has been drawn (at least using Qt4Agg/TkAgg - but not MacOSX - with matplotlib 1.4.0):
Try commenting out the
fig = ...
lineUSING plt.rcParams
There is also this workaround in case you want to change the size without using the figure environment. So in case you are using
plt.plot()
for example, you can set a tuple with width and height.This is very useful when you plot inline (e.g. with IPython Notebook). As @asamaier noticed you is preferable to not put this statement in the same cell of the imports statements.
Conversion to cm
The
figsize
tuple accepts inches so if you want to set it in centimetres you have to divide them by 2.54 have a look to this question.The first link in Google for
'matplotlib figure size'
is AdjustingImageSize (Google cache of the page).Here's a test script from the above page. It creates
test[1-3].png
files of different sizes of the same image:Output:
Two notes:
The module comments and the actual output differ.
This answer allows easily to combine all three images in one image file to see the difference in sizes.
This works well for me:
This might also help: http://matplotlib.1069221.n5.nabble.com/Resizing-figure-windows-td11424.html