0

Using following code to get axis position and the ration of weight and height.

import matplotlib.pyplot as plt
ss = 2.4
fig, ax = plt.subplots(1, 1, figsize=(ss, ss))
box = ax.get_position()
box.width/box.height

Set ss=2.4, 3.6, 7.2, the output in my PC is always the same:

1.0064935064935066

Backend: %matplotlib qt

Why not get the width and height the same value?

1
  • Any reason to have such inconstancy? Any numerical consideration? Commented Mar 14, 2019 at 12:06

1 Answer 1

1

There is per se no reason that an axes should be square, just because the figure it lives in is square.

The subplot parameters set by the default rc file are

figure.subplot.left    : 0.125  ## the left side of the subplots of the figure
figure.subplot.right   : 0.9    ## the right side of the subplots of the figure
figure.subplot.bottom  : 0.11   ## the bottom of the subplots of the figure
figure.subplot.top     : 0.88   ## the top of the subplots of the figure

such that

(right-left)/(top-bottom) = (0.9-0.125)/(0.88-0.11) = 1.0064935

Of course you can set those parameters to your liking and hence optain a square subplot, either in your rc file, or via code, e.g.

rc = {"figure.subplot.left"    : 0.1, 
      "figure.subplot.right"   : 0.9,
      "figure.subplot.bottom"  : 0.1,
      "figure.subplot.top"     : 0.9 }
plt.rcParams.update(rc)

or

fig.subplots_adjust(left=0.1, bottom=0.1, right=0.9, top=0.9)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, one more way to generate square axes are fig.add_axes([0.1, 0.1, 0.8, 0.8]), which is is useful for me to fine tune the position of the axes.

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.