-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plot_date() after axhline() doesn't rescale axes #7742
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
Comments
@Yasaman-Mah import matplotlib.pyplot as plt
from datetime import datetime
dates = [datetime(2016, 1, 1, 0, 0, 0), datetime(2016, 1, 2, 0, 0, 0)]
values = [1, 2]
expected_limits = (xmin, xmax) # fill this in
fig, (ax1, ax2) = plt.subplots(2, 1)
ax1.axhline(1.5)
ax1.plot(dates, values)
ax2.plot(dates, values)
ax2.axhline(1.5)
assert ax1.get_xlim() == expected_limits
assert ax1.get_xlim() == ax2.get_xlim() I think it'd be fine to place this in |
@Yasaman-Mah Looking forward to seeing your PR! |
@Yasaman-Mah
|
Modified axhline() function to save state of ignoring limits and restore after plotting the line
I also encountered what @Shang-Jia said and I have submitted a PR #8210 that fixes all issues discussed. |
@Shang-Jia To matplotlib developers: Thank you for all the feedback. Unfortunately, to me it seems that some of my classmates are trying to take credit for most of my fix by making minor improvements to it. In fact, I do have a better solution in mind, which I will start working on once the situation above is resolved. |
Fixes matplotlib#7742 - axhline rescale issue
It looks like we have code in master that is designed to handle this (autoscaling with the mixed transform should be leaving x limits scaling alone), but the original example now yields a traceback:
|
(ahem, or if you register the date converter manually) |
Merged and verified: the bug reported here still exists. |
This isn't just dates, this is all units. Basically if the units change on an axes (as they do here from no units to date units) This doesn't happen if the new I don't know why |
Thanks to everyone who worked on fixing this! I remember opening this in the early days of my contributions to Matplotlib, so great to finally see it fixed! |
If I plot an
axhline
first, and then two points withplot_date
, the x-axis is not rescaled to the two new data points:I would expect the two plots to be the same, and the plotting order not to matter.
Present on current master (2.0.0rc2.post2912+g015d8d5) and on 1.5
The text was updated successfully, but these errors were encountered: