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

Propagate Axes class and kwargs for twinx and twiny#29325

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

Conversation

cmp0xff
Copy link
Contributor

@cmp0xffcmp0xff commentedDec 16, 2024
edited
Loading

PR summary

Why is this change necessary?

Users may wish to inheritmatplotlib.axes.Axes, see e.g.https://stackoverflow.com/q/48593124.

  • In such applications,twinx /twiny in the subclass should return subclass instances, instead ofAxes.
  • If the subclass supports additionalkwargs,twinx /twiny should also be able to accept these extra arguments.

What problem does it solve?

The proposed changes fix the behaviour of the methods mentioned above..

What is the reasoning for this implementation?

We try to keep the changes to a minimum and maintain current behaviours.

PR checklist

@cmp0xffcmp0xff marked this pull request as ready for reviewDecember 16, 2024 16:35
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch from687849d tob1d6a54CompareDecember 16, 2024 19:27
@timhoffm
Copy link
Member

I'm somewhat hesitant to do this. While it looks feasible at first glance, I've some reservations:

  • What is the use case? The examples in the stackoverflow link seem a bit far fetched. Are we really solving a problem with this, or are we just improving on how one can abuse the library?
  • twinx/twiny is currently limited toAxes. I'd be happy to simply document that limitation. Twinning is likely confusing or even not feasible on non-rectangular coordinate systems - polar plots are such a case. When opening up to other Axes subclasses, we allude that it works ("does the right thing") there, but I have absolutely no clue whether that'd be the case.

@cmp0xff
Copy link
ContributorAuthor

cmp0xff commentedDec 17, 2024
edited
Loading

Hi@timhoffm , thank you for the comments.

Twinning is powerful for time serieses with different units

Twinning is likely confusing or even not feasible on non-rectangular coordinate systems - polar plots are such a case.

When plotting time series data, it happens that several serieses with different units are to be shown in a single figure, with which users would like to interact. One can use the time labels as the shared x axis to twin two overlapping subplots, each has its own y axis with its own unit. This enables simultaneous interaction on the subplots; paning and zooming in one subplot act in the same way on the shared axes of both subplots.

SubclassingAxes

Are we really solving a problem with this, or are we just improving on how one can abuse the library?

Being able to subclassAxes is both a potential for the user, AND a feature ofmatplotlib.

  • The existence ofaxes_class as a public argument inFigure.add_subplot andFigure.add_axes already shows this.
  • Inmpl_toolkits.axisartist, we have an example of subclassingAxes.
  • In_AxesBase._make_twin_axes, which is only used bytwinx andtwiny, we already have the potential to insert*args and**kwargs. However they were not in use before the current MR.

@rcomer
Copy link
Member

rcomer commentedDec 17, 2024
edited
Loading

@cmp0xff could you give an example of a use-case where you need both a subclass and a twinned axes? I appreciate the value of subclasses and I have added functionality to Matplotlib to handle them (#22608). For that PR I had a specific subclass in mind (the Cartopy GeoAxes) as shown in the PR summary. Do you have a specific subclass in mind for this?

cmp0xff reacted with eyes emoji

@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch fromb1d6a54 to2feddadCompareDecember 17, 2024 21:14
@cmp0xff
Copy link
ContributorAuthor

Hi@rcomer , thank you for your hints. After some research, I have realised that what I described above has mostly been implemented byparasite_axes in theaxisartist toolkit.

In practise, we have an in-house extension ofmatplotlib.axes.Axes which also implementsresampling, wheretwinx is also needed. However, the function returns anAxes instance, instead of instantiating the extended Axes. Therefore the wholetwinx function needs to be reimplemented, which is almost entirely the same with the originaltwinx, with the single addition that the extended Axes class is returned.

Now that in3.10.0,twinx has been updated, we need to propagate the changes to our reimplementation. What if the originaltwinx could be adapted a bit, so that it could become more flexible and handle subclasses? This was the motivation of the current MR.

rcomer reacted with thumbs up emoji

@timhoffm
Copy link
Member

Thanks, this sounds like a reasonable application. I'm fundamentally ok with extending/modifying the behavior oftwinx().

Design considerations:

  • It may make sense to twin an Axes subclass of another type, e.g. you could twin yourResamplingAxes to a regularAxes. This would require an explicitaxes_class parameter:ax.twinx(axes_class=ResamplingAxes). This should be made explicit and not folded into kwargs. A corollary is that the return type would stayAxes (or the signature must be overloaded).
  • If we take anaxes_class parameter, should the default beAxes (current behavior, maximal compatibility) orSelf (possibly slightly more common application)?

cmp0xff added a commit to cmp0xff/matplotlib that referenced this pull requestDec 20, 2024
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch from2feddad toa9c8ca4CompareDecember 20, 2024 23:12
cmp0xff added a commit to cmp0xff/matplotlib that referenced this pull requestDec 20, 2024
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch froma9c8ca4 tob337f94CompareDecember 20, 2024 23:13
cmp0xff added a commit to cmp0xff/matplotlib that referenced this pull requestDec 21, 2024
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch fromb337f94 toa228f5dCompareDecember 21, 2024 10:28
@cmp0xff
Copy link
ContributorAuthor

Hi@timhoffm ,

It may make sense to twin anAxes subclass of another type, e.g. you could twin yourResamplingAxes to a regularAxes. This would require an explicitaxes_class parameter:ax.twinx(axes_class=ResamplingAxes). This should be made explicit and not folded intokwargs. A corollary is that the return type would stayAxes (or the signature must be overloaded).

c4c3aa7

If we take anaxes_class parameter, should the default beAxes (current behavior, maximal compatibility) orSelf (possibly slightly more common application)?

After some thinking, I would go for keeping the current behaviour, defaulting toNone (rather thanself).

The reason is that some subclasses useprojection orpolar to instantiate themselves; these parameters are incompatible withaxes_class, which should hence stayNone for these subclasses.

timhoffm and rcomer reacted with thumbs up emoji

cmp0xff added a commit to cmp0xff/matplotlib that referenced this pull requestDec 21, 2024
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch fromde198d2 toecb384eCompareDecember 21, 2024 22:55
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch from3b117c0 to18589f3CompareDecember 27, 2024 10:38
@cmp0xff
Copy link
ContributorAuthor

Hi, it has been two weeks since the last update. May I ask for a second approval / a critical review? Thanks and happy new year.

Copy link
Member

@rcomerrcomer left a comment

Choose a reason for hiding this comment

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

Thanks@cmp0xff, I just have some comments on the docstrings.

cmp0xff reacted with thumbs up emoji
cmp0xff added a commit to cmp0xff/matplotlib that referenced this pull requestJan 8, 2025
…lib#29325 (comment)Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch fromdf825b1 to883f049CompareJanuary 8, 2025 10:39
@rcomerrcomer added this to thev3.11.0 milestoneJan 8, 2025
@cmp0xffcmp0xffforce-pushed thefeature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branch from883f049 tobb8e374CompareJanuary 8, 2025 10:59
@rcomerrcomer merged commit8d3c4db intomatplotlib:mainJan 8, 2025
39 checks passed
@cmp0xffcmp0xff deleted the feature/cmp0xff/axes-class-and-kwargs-for-twinx-and-twiny branchJanuary 8, 2025 15:11
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

@rcomerrcomerrcomer approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

3 participants
@cmp0xff@timhoffm@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp