+2 votes
2 views
in Python by (10.2k points)
edited by

Can someone tell me any methods change the size of figures drawn with matploatlib?

3 Answers

0 votes
by (2k points)
edited by

It's a very simple task to perform, just use figure and it will tell you the call signature:

from matplotlib.pyplot import figure
figure(num=None, figsize=(3, 4), dpi=80, facecolor='k', edgecolor='w')

(1,1,) in figsize will create a inch-by-inch plot and it'll be of 80-by-80 (defined in dpi) pixels. 

0 votes
by (107k points)

You can use the below-mentioned code if you want to change the figure that is drawn with Matplotlib:

fig = matplotlib.pyplot.gcf()

fig.set_size_inches(18.5, 10.5)

fig.savefig('test2png.png', dpi=100)

Now if you need to propagate the size change to an already existing GUI window, then add 'forward=True'

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

You can use the following video tutorials to clear all your doubts:-

0 votes
by (108k points)

If you are working with plt.plot(), you can simply use the set a tuple with your respective width and height like:

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = (20,3)

The above code is very beneficial when you plot inline means with IPython Notebook. 

For more information regarding the same, do refer to the Python tutorial that will help you out in a better way.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 30, 2020 in Python by laddulakshana (11.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...