New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
axis limits don't coordinate with each other #13648
Comments
I think you are asking that the y limits should auto-scale based on what is
visible in the new x limits?
…On Mon, Mar 11, 2019 at 3:21 AM Jian Shi ***@***.***> wrote:
Bug report
*Bug summary*
In matplotlib, when manually restricting xlim, ylim does not change
accordingly.
*Code for reproduction*
import numpy as npimport matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6,7])
y = x
fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))
fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)
ax.set_xlim(1, 2)print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))
*Actual outcome*
xlim: (0.7, 7.3), ylim: (0.7, 7.3)
xlim: (1.0, 2.0), ylim: (0.7, 7.3)
*Expected outcome*
When I change xlim to (1, 2), I expect ylim to change accordingly (because
y's value range becomes [1, 2], now that x's range shrinks), but ylim still
remains (0.7, 7.3). In fact, in MATLAB xlim and ylim can coordinate with
each other.
MATLAB codes to reproduce this behavior:
x = [1,2,3,4,5,6,7];
y = x;
figure; plot(x, y);
figure; plot(x, y); xlim([1, 2]);
*Matplotlib version*
- Operating system: Windows 10
- Matplotlib version: 2.2.2
- Matplotlib backend (print(matplotlib.get_backend())):
module://ipykernel.pylab.backend_inline
- Python version: 3.6.6
- Jupyter version (if applicable): N/A
- Other libraries: N/A
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13648>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AARy-IjW4eBJON_iRc5u07wPaxs1J_zJks5vVgPdgaJpZM4bn8pA>
.
|
... I think there are just as many people who would complain about that behaviour as might appreciate it. I used Matlab for many years and don't recall it doing this, but perhaps I've forgoten. |
@WeatherGod Yes, that is what I meant. I did try to set autoscale (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.autoscale.html), but I could not get it to work due to lack of an official example. @jklymak I think matplotlib can offer users the option to turn it on and off easily. |
This was discussed and rejected in #9890. It would also require a pretty deep rewrite of the way data limits are computed. |
@anntzer So autoscale and set_autoscale_view currently just do nothing? (I tried autoscale and the poster in #9890 tried set_autoscale_view.) If they are not for this purpose, then I would suggest an update on the official documentation, because it is quite vague to a user as currently written: "matplotlib.pyplot.autoscale(enable=True, axis='both', tight=None) Autoscale the axis view to the data (toggle). Convenience method for simple axis view autoscaling. It turns autoscaling on or off, and then, if autoscaling for either axis is on, it performs the autoscaling on the specified axis or axes." |
autoscale/autolim works on all collections. It asks each artist object and
collection for their bounding box and selects a limit that encompasses the
union of those bounding boxes. The feature that isn't implemented is to
figure out what the bounding box would be if one were to start with a
constraint. Not impossible to code, but it would be fairly extensive amount
of work.
…On Mon, Mar 11, 2019 at 4:03 PM Jian Shi ***@***.***> wrote:
@anntzer <https://github.com/anntzer> So autoscale and set_autoscale_view
currently just do nothing? (I tried autoscale and the poster in #9890
<#9890> tried
set_autoscale_view.)
If they are not for this purpose, then I would suggest an update on the
official documentation, because it is quite vague to a user as currently
written:
"matplotlib.pyplot.autoscale(enable=True, axis='both', tight=None)
Autoscale the axis view to the data (toggle).
Convenience method for simple axis view autoscaling. It turns autoscaling
on or off, and then, if autoscaling for either axis is on, it performs the
autoscaling on the specified axis or axes."
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13648 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-OelMECLhdlTYN0rKFBwd3v_KhLKks5vVraDgaJpZM4bn8pA>
.
|
Thanks for the explanation. I understand it would be a lot of work to implement this. So I guess a good compromise is to note this default in the documentation. |
Let us know where you think the documentation is deficient. The autolimit
feature has been default for 10 or more years now.
…On Mon, Mar 11, 2019 at 5:50 PM Jian Shi ***@***.***> wrote:
Thanks for the explanation. I understand it would be a lot of work to
implement this. So I guess a good compromise is to note this default in the
documentation.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13648 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-LCYbTm3AZqet8l2E2vDzQfZXoabks5vVs-KgaJpZM4bn8pA>
.
|
With this short script below, I can confirm two different behaviors:
However, by reading the current documentation (https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale.html), I could only expect Behavior No. 1, but not Behavior No. 2. So this is where I think the documentation can benefit from some improvements. import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6,7])
y = x
fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))
ax.autoscale(enable=False)
y1 = 2 * x
ax.plot(x, y1) # ylim is not allowed to stretch
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))
ax.autoscale(enable=True)
y2 = 2 * x + 1
ax.plot(x, y2) # ylim stretches automatically
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))
ax.autoscale(enable=True)
y3 = 2 * x + 2
ax.set_xlim(1, 2)
ax.plot(x, y2) # ylim does not shrink automatically
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim())) |
This issue is still valid. The work is to add another paragraph to the |
Closing as a duplicate of #2123. |
Bug report (or feature request)
Summary
In
matplotlib
, when manually restrictingxlim
,ylim
does not change accordingly.Code for reproduction
Actual outcome
Expected outcome
When I change xlim to (1, 2), I expect ylim to change accordingly (because y's value range becomes [1, 2], now that x's range shrinks), but ylim still remains (0.7, 7.3). In fact, in MATLAB xlim and ylim can coordinate with each other.
MATLAB codes to reproduce this behavior:
Matplotlib version
print(matplotlib.get_backend())
):module://ipykernel.pylab.backend_inline
The text was updated successfully, but these errors were encountered: