How To Stretch/Scale Figure Size in Matplotlib

Viewed 24

How do I stretch the current figure size in matplotlib? For example, make it twice as wide but keeping the same height.

NOTE: I do not want to just set the figsize to something new. I want to double the existing width, whatever it is. This is not a duplicate question of how to set the figure size.

1 Answers
fig_width, fig_height = plt.gcf().get_size_inches()
fig = plt.figure(figsize=(fig_width*2, fig_height))

You can get the default, or current, figure size parameters using plt.gcf().get_size_inches().

Then set a new figure size by scaling these values and creating a figure with figsize as an argument. In this case, the width is doubled but height kept the same.

Related