ChrisGuest ChrisGuest - 1 year ago 310
Python Question

Specify subplot size instead of figsize in matplotlib

I am using matplotlib to draw some graphs. Usually, standard practice is to start with a Figure's dimensions and specify the axes' dimensions so that the graph is then scaled to the available space.

However I have a request to extend the height of a graph to accommodate outlying data on the y axis.

I know that I can use

to specify overall dimensions, but this won't keep the the graphs in proportion once a margin has been included. Is there a way to specify the actual subplot size or conversely to determine the margin size for the default margin size and adjust the Figure's dimensions accordingly?

Answer Source

You mean something like this? You need to calculate margins.

import matplotlib.pyplot as plt


left = 0.5*(1.-subplotsize[0]/figuresize[0])
right = 1.-left
bottom = 0.5*(1.-subplotsize[1]/figuresize[1])
top = 1.-bottom
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download