2

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 Figure.figsize 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?

1 Answer 1

2

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

import matplotlib.pyplot as plt

subplotsize=[5.,5.]
figuresize=[10.,10.]   

left = 0.5*(1.-subplotsize[0]/figuresize[0])
right = 1.-left
bottom = 0.5*(1.-subplotsize[1]/figuresize[1])
top = 1.-bottom
fig=plt.figure(figsize=(figuresize[0],figuresize[1]))
fig.subplots_adjust(left=left,right=right,bottom=bottom,top=top)
ax=fig.add_subplot(111)
plt.show()
Sign up to request clarification or add additional context in comments.

3 Comments

That's pretty close to what I wanted. Instead of specifying a fixed value for figuresize=[10.,10.], I did this:
margin_left = 1.0; margin_right = 1.0; margin_top = 1.0; margin_bottom = 1.0
figuresize = [margin_left + subplotsize[0] + margin_right, margin_top + subplotsize[1] + margin_bottom]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.