3

Consider the following code:

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca()
circle = plt.Circle((0, 0), radius = 0.5)
ax.add_patch(circle)
print(plt.axis())
plt.show()

The default axis limits are printed as:

(0.0, 1.0, 0.0, 1.0)

I am not sure why this is the case. So, I would like to learn why?

PS: I know I can just do plt.axis('scaled') so that I can see the entire circle.

asked Nov 9, 2014 at 3:34

1 Answer 1

4

Plotting functions like plot or scatter make use of the function autoscale_view (source). However, add_patch does not call it (source). While this explains why the axes are not scaled automatically in your example, I'm not sure what the underlying design choice was.

answered Nov 12, 2014 at 17:00
5
  • Does that answer your question? If not, what exactly is your question? Commented Nov 12, 2014 at 22:41
  • the question is "why" - the part that you are not sure about. Commented Nov 12, 2014 at 22:51
  • I see. I guess @tcaswell knows the answer Commented Nov 12, 2014 at 22:57
  • 3
    @hizg I just tried callling autoscale_view() and it fixes my issue. submitted a PR: github.com/matplotlib/matplotlib/pull/3936 Commented Dec 20, 2014 at 0:54
  • 3
    Please consider updating the answer with ax.autoscale_view() as a recipe. Commented Nov 16, 2019 at 20:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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