Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Added share_tickers parameter to axes._AxesBase.twinx/y#7528

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

madphysicist
Copy link
Contributor

Allow a copy ofAxis.minor andAxis.major objects to be made when axes are twinned. This will allow two twinned axes to have differentFormatter andLocator objects when they are both visible. The default of always sharing the same references (via a sharedmatplotlib.axis.Ticker container) has been preserved.

I made the keyword parametershare_tickers propagate all the way toaxes._AxesBase.__init__ rather than implementing the copy inaxes.AxesBase._make_twin_axes. The reason is that I would like to be able to modify the meaning ofsharex andsharey directly in the constructor.

Fixes#7376.

This PR includes tests.

A couple of places that I would ask reviewers to look at:

  • I made one functional change that I think is OK, but may need to be reverted. In axes/_base.py, around line 1004, where the formatter and locator get reset, the original code calledAxis.set_major/minor_formatter/locator. This would set theaxis attribute of the locators and formatters to the second axis, not the original one thattwinx/y was called on in the first place. I have gone ahead and changed that behavior for both theshared_ticker=True case and theFalse case. For theFalse case this is pretty obvious, since we do not want to change theaxis attribute of the original formatter and locator at all. It should not cause any problems in theTrue case either, but it is technically a minor change in the functionality that I would like to bring attention to.
  • Did I add documentation for theshare_tickers parameter correctly in axes/_base.py:473?
  • Did I add the handling of the parameter correctly? Specifically, it will affect the axis key inFigure._make_key. I think that this is correct because the axes with and withoutshare_tickers will serve different purposes visually, so it should be OK to treat them as different objects.
  • I did not add an explicit test for the new copy constructor ofaxis.Ticker because it is really trivial. However, the code does get complete coverage in the tests that I wrote fortwinx/y.

@madphysicist
Copy link
ContributorAuthor

@efiring. I made the parameter have to be explicitly specified by the user. The default is to share the ticker. Initially, even if the container is not shared, the actual Locator and Formatter are. It is then up to the savy user to mess things up for themselves.

@efiring
Copy link
Member

efiring commentedNov 28, 2016 via email

On 2016/11/28 12:53 PM, Joseph Fox-Rabinovitz wrote: It is then up to the savy user to mess things up for themselves.
The problem is that when they do that, they tend to come back to us andcomplain.

@madphysicist
Copy link
ContributorAuthor

Given the way I structured it, the user has to first manually disable theshare_tickers option when twinning, then explicitly change one of the locators. I think that adding a warning in the docs about being careful with auto scaling should be enough since the default behavior is unchanged. Keep in mind that even withshare_tickers disabled, the twinned axis will share a reference to the original locator until the user explicitly changes it. I just added a way to make such a change possible as a non default behavior.

@madphysicist
Copy link
ContributorAuthor

@efiring Hopefully the explicit warnings I added in the documentation will be sufficient. Perhaps I should add an actual warning to the low-level functions that set up auto-scaling that will be triggered ifself._share* is non-None andself._share_tickers isFalse?

@codecov-io
Copy link

codecov-io commentedNov 29, 2016
edited
Loading

Current coverage is 61.90% (diff: 100%)

Merging#7528 intomaster will decrease coverage by4.52%

@@             master      #7528   diff @@==========================================  Files           109        173     +64     Lines         46780      56171   +9391     Methods           0          0             Messages          0          0             Branches          0          0           ==========================================+ Hits          31075      34771   +3696- Misses        15705      21400   +5695  Partials          0          0

Powered byCodecov. Last updatedfd38f7...eb18ba8

@madphysicistmadphysicistforce-pushed thetwin-ticker-copy branch 2 times, most recently from54c9995 to890c8b7CompareDecember 1, 2016 23:07
@QuLogic
Copy link
Member

I think you push some commits for#7482 on here accidentally.

@madphysicist
Copy link
ContributorAuthor

madphysicist commentedDec 2, 2016
edited
Loading

@QuLogic. It was not entirely an accident. I wanted to make the documentation change in the example once (if) both branches get merged. That last commit should be in whichever branch gets merged last. My mistake was pushing it here early.

@madphysicist
Copy link
ContributorAuthor

Sorry, pushing all kinds of buttons unintentionally in mobile version.

@madphysicist
Copy link
ContributorAuthor

@QuLogic. I undid the push. Once either PR gets accepted, I will add the example modifications to the other one. Thanks for the catch.

@madphysicist
Copy link
ContributorAuthor

While I realize that I need to add more tests for things like subplots using the new keyword, is the failure in coveralls something I should be worried about in general?

@naoyak
Copy link
Contributor

@madphysicist do you have a screenshot of what this would look like (i.e. a shared axis with 2 distinct ticker formats)? I'm working on#7904 and wanted to be sure things would be consistent in terms of approach.

@madphysicist
Copy link
ContributorAuthor

@naoyak. Thanks for reaching out. I am glad to see you working on the auto-scaling, which I know next to nothing about. There is a screenshot of the expected behavior ina comment I made in the issue that started this PR. It also has the code used to generate it. The portion of the discussion following that comment also has some points by@efiring about autoscaling. I am not sure if they are pertinent to your PR though.

@naoyak
Copy link
Contributor

Awesome, the screenshot helps. I don't think our PRs will clash in any way but if you are close to finishing this one up, I might just wait and rebase on top.

@madphysicist
Copy link
ContributorAuthor

I agree that there will likely be no clash. I was wondering if you have any thoughts aboutthis comment. If the twinned axes have different locators and autoscaling is turned on, is there really a possibility for conflict between the locators? If so, how would you recommend resolving it?

@naoyak
Copy link
Contributor

What do we mean here when we talk about a conflict in autoscaling? Do you mean that one of the twinnedAxes would have autoscaling turned on, and the other has it turned off? In any case, new data would only apply to one of theAxes, I think.

@madphysicist
Copy link
ContributorAuthor

@naoyak Going off the comment I linked to in my previous post, there may be the possibility that the locator is used to determine bounds when autoscaling is turned on. Since my PR will allow different locators on each of the twinned axes, which one will determine the final bounds that are set (assuming that both have autoscaling on simultaneously, as they should)? I am not 100% convinced that there is a possibility for conflict at all, but I have not traced through the code enough or done any experiments to confirm one way or the other. I thought you might have more insight into the possibilities.

@tacaswelltacaswell added this to the2.1 (next point release) milestoneJan 27, 2017
@@ -604,6 +604,14 @@ class Ticker(object):
locator = None
formatter = None

def __init__(self, ticker=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I have a slight preference to stay with the pattern theArtists use of anupdate_from method, but not enough to hold up the PR over.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I have no problem doing it that way too. Functionally it won't make a difference what the name of the method is.

self.xaxis.set_minor_locator(minl)
# Reset the formatter/locator. Axis handle gets marked as
# stale in previous line, no need to repeat.
if self._share_tickers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I am confused, it looks like this behavior is what Ithought it was, but the other behavior is what it used to do.

Copy link
ContributorAuthor

@madphysicistmadphysicistJan 27, 2017
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The old way of doing things was:

  1. Copy theTicker objects to the new axis (lines 973-4)
  2. Save the formatters and locators (lines 979-982)
  3. Trash the formatters and locators with_set_scale (line 985)
  4. Restore the formatters and locators (lines 988-991)

This would restore for both the old and new axis since they always shared the sameTicker object.

I made this process a little more efficient:

  1. Set emptyTickers for the new axis (this one) (lines 993-4)
  2. Let_set_scale mess with the emptyTickers (line 1001)
  3. Reset theTickers to either a reference (lines 1006-7) or a copy (lines 1009-10) of the old axis'sTickers.

Since_share_tickers defaults toTrue, the original behavior of having a reference to the original axis'Tickers is preserved unless explicitly asked for by the user. The key here is that_set_scale messes up the formatters and locators for its own purposes and it's effects have to be undone one way or another. I think my way is just simpler.

@madphysicist
Copy link
ContributorAuthor

@tacaswell I switchedTicker to useupdate_from and I think it makes the code look better overall. Also saves on an allocation whenself._share_tickers isFalse.

@madphysicist
Copy link
ContributorAuthor

Looks like everything is working. However, I would like to add a couple of tests with subplots and autoscaling before this gets merged.

story645 reacted with thumbs up emoji

@madphysicistmadphysicistforce-pushed thetwin-ticker-copy branch 3 times, most recently from202f91b to546713eCompareJanuary 31, 2017 14:50
@tacaswelltacaswell modified the milestones:2.1 (next point release),2.2 (next next feature release)Aug 29, 2017
@dstansby
Copy link
Member

Closing in favour of discussion on#10976, and as a duplicate of#10960.

@dstansbydstansby removed this from theneeds sorting milestoneApr 6, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@madphysicist@efiring@codecov-io@QuLogic@naoyak@dstansby@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp