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
user59634user59634
1 Answer 1
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
-
Does that answer your question? If not, what exactly is your question?hitzg– hitzg2014年11月12日 22:41:49 +00:00Commented Nov 12, 2014 at 22:41
-
the question is "why" - the part that you are not sure about.user59634– user596342014年11月12日 22:51:51 +00:00Commented Nov 12, 2014 at 22:51
-
I see. I guess @tcaswell knows the answerhitzg– hitzg2014年11月12日 22:57:29 +00:00Commented 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/3936user59634– user596342014年12月20日 00:54:17 +00:00Commented Dec 20, 2014 at 0:54
-
3Please consider updating the answer with
ax.autoscale_view()
as a recipe.Ben Usman– Ben Usman2019年11月16日 20:09:05 +00:00Commented Nov 16, 2019 at 20:09
lang-py