-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[MRG+1] plot_date() after axhline() doesn't rescale axes #8205
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
Conversation
lib/matplotlib/tests/test_axes.py
Outdated
@@ -4972,3 +4972,21 @@ def test_bar_single_height(): | |||
ax.bar(range(4), 1) | |||
# Check that a horizontal chart with one width works | |||
ax.bar(0, 1, bottom=range(4), width=1, orientation='horizontal') | |||
|
|||
def test_datetime_axhline_same_axes(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pep8 checker is probably going to want 2 blank lines between functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you'll also need to trim trailing whitespace:
https://travis-ci.org/matplotlib/matplotlib/jobs/208246492#L1683
Next time, please add a meaningful title to the pull requests. The reference to the ticket should be in in the description of the PR (else it is non clickable). |
Modified axhline() function to save state of ignoring limits and restore after plotting the line
This solution will always reset the existing_data_limits so on the following execution |
@Shang-Jia This is a preliminary solution, I submitted this pull request to get some feedback from matplotlib team before going on with another solution. |
This looks good to me. Thanks for the patch and sorry it took so long to get feedback! |
@@ -725,6 +725,7 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs): | |||
trans = self.get_yaxis_transform(which='grid') | |||
l = mlines.Line2D([xmin, xmax], [y, y], transform=trans, **kwargs) | |||
self.add_line(l) | |||
self.ignore_existing_data_limits = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a symmetric change to axvline
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have made a similar change to axvline
. Please see my comment below before approving the changes.
@Yasaman-Mah It's good you pointed that out. However I still think that this PR is a useful contribution and should be merged. This PR fixes #7742 (which produces clearly wrong output), and although it does introduce a side effect, the side effect is not "wrong output", but only slightly inconsistent for a certain specific order of input. And as you pointed out, it would require MUCH more work to fix this inconsistency, because introducing two symmetric flags "ignore_y_limits" and "ignore_x_limits" is a significant architectural change. Hence I would ask @NelleV @tacaswell to review this PR again. Can we go ahead with this fix? |
What are dates (which are just input with units) behaving differently than plain numbers? I am still not sure I understand what the The code and the figure above seem out of sync with each other, but I would not call that a 'side effect'. IT looks like the bug from #7742 (order dependent limits) has just been moved to different (and probably more common) case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not sure I understand what is going on here.
Anyone who can may clear this review.
Can this PR be resurrected or closed? |
I'm closing for now - but feel free to re-open if someone wants to champion this PR. Thanks for the contribution. |
The only reason that plotting axhline first changes behaviour of plotting datetime is that it sets ignore_existing_data_limits to false and then when plotting datetime data, default datetime data limits are taken into consideration.
Unfortunately this fix would affect y data limits too. I think a better solution would be to have two variables ignore_existing_x_limits and ignore_existing_y_limits, but I am not sure if adding more detail and making it slightly more complicated just because of axhline makes sense.
ref #7742