Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix inconsistency between set_xlim and set_view_interval #6890

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

Closed
wants to merge 9 commits into from

Conversation

syrte
Copy link

@syrte syrte commented Aug 3, 2016

Fix bug:
Axes.xaxis.set_view_interval , Axes.xaxis.set_view_interval do not
update twin axis as Axes.set_xlim do.

Add function:
Axes._set_viewLim_intervalx, Axes._set_viewLim_intervaly, they aim at change viewLim.intervalx(y) and reduce the axes's callbacks and update the twin axis.

Refer the issue #6863

Fix bug:
`Axes.xaxis.set_view_interval` , `Axes.xaxis.set_view_interval` do not
update twin axis as `set_xlim` do.

Add function:
`Axes._set_viewLim_intervalx`, `Axes._set_viewLim_intervaly`
Fix error in previous commit.
@tacaswell tacaswell added this to the 2.0.1 (next bug fix release) milestone Aug 3, 2016
@tacaswell
Copy link
Member

It looks like the test failures are pep8/pycodestlye releated.

We use and automated tool to check style consistency across the library. It seems silly, but for a library this big with this many contributors the consistent code style really does help.

You have two lines that are too long.

Could you also add a test, probably in test_axes. Something like

@cleanup
def test_twinx_veiw_interval():
    fig, ax = plt.subplots()
    ax2 = ax.twinx()
    # do the thing that exposed the bug
    # assert that it is behaving correctly now

to make sure that this bug does not creep back in.

@syrte
Copy link
Author

syrte commented Aug 3, 2016

I feel that self.axis.set_view_interval should also under the control of Axes._autoscaleXon like autoscale_view, then once we called xlim then the axes limit will be fixed, though later xticks may excess the range. Does this make sense?

A stupid question, which place is better for the discussion, in PR or in original issue?

@tacaswell
Copy link
Member

Here is probably better (as it is attached to the code).

I think it comes down to how we should interpret user intent. If the user calls set_xticks then the user is saying "I want my ticks to be exactly at these places" (under the hood it switches to using a FixedLocator) and so the user probably means that those values are interesting and should be include so the limits should be extended to include them. That intent should take priority over the earlier instruction to 'show this region'.

Expanding the view internal on set_xticks has been like that for a long time and many people maybe relying on the view-expanding behavior. Possibly breaking user code (with the exception of breaking work-arounds to bugs) makes changes have a much higher bar to be accepted.

@syrte
Copy link
Author

syrte commented Aug 4, 2016

Reasonable, I agree with you.

@tacaswell
Copy link
Member

It looks like there are a couple of other places where viewLim is being directly set:

22:21 $ git grep -n '\.viewLim.interval.*='
lib/matplotlib/axes/_base.py:2876:        self.viewLim.intervalx = (left, right)
lib/matplotlib/axes/_base.py:3150:        self.viewLim.intervaly = (bottom, top)
lib/matplotlib/axis.py:2005:                self.axes.viewLim.intervalx = xmin, xmax
lib/matplotlib/axis.py:2345:                self.axes.viewLim.intervaly = ymin, ymax
lib/matplotlib/projections/polar.py:587:        self.viewLim.intervalx = (0.0, np.pi * 2.0)
lib/matplotlib/ticker.py:226:        self.viewLim.intervalx = vmin, vmax

While you are working on this could you clean those up too?

@syrte
Copy link
Author

syrte commented Aug 4, 2016

For ticker.py, it's in class _DummyAxis(object). This class is not a subclass of Axis and seems to be a placeholder or something similar for internal use in ticker.Formatter. I didn't see the relation with real axis of axes but not very sure.

The rest I'll check them later. It occurs more than I thought. And we shall take care of every '\.viewLim.*=' not only '\.viewLim.interval.*='...

@QuLogic QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0.2 (next bug fix release) May 3, 2017
@syrte
Copy link
Author

syrte commented Sep 20, 2017

Sorry, still have no time for this PR. I'm busy working on my thesis.
Many thanks, if anyone feels interested in this problem and wants to take over.

@tacaswell tacaswell modified the milestones: 2.1.1 (next bug fix release), 2.2 (next feature release) Oct 9, 2017
@jklymak
Copy link
Member

jklymak commented May 2, 2018

Closing as not active. Feel free to re-open if someone feels the need...

@jklymak jklymak closed this May 2, 2018
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants