Skip to content

Update secondary_axis tutorial#29073

Merged
timhoffm merged 5 commits into
matplotlib:mainfrom
dkweiss31:secondary_axis_interp_fix
Nov 21, 2024
Merged

Update secondary_axis tutorial#29073
timhoffm merged 5 commits into
matplotlib:mainfrom
dkweiss31:secondary_axis_interp_fix

Conversation

@dkweiss31
Copy link
Copy Markdown
Contributor

@dkweiss31 dkweiss31 commented Nov 5, 2024

PR summary

Closes #29067
Fixes a small issue with the secondary_axis tutorial where the interpolation from one axis to the other needs to be defined outside the bounds of the data that is plotted. This was previously noted in the tutorial but was not implemented correctly. The example in question has been simplified and updated so that the secondary axis is correctly derived from the primary axis.

PR checklist

…rom the first. In this case the interpolation must be defined outside the bounds of the data that is plotted. Moreover the tutorial in question has been simplified.
@github-actions github-actions Bot added the Documentation: examples files in galleries/examples label Nov 5, 2024
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Comment thread galleries/examples/subplots_axes_and_figures/secondary_axis.py Outdated
make endpoints large in magnitude

Co-authored-by: Jody Klymak <jklymak@gmail.com>
@dkweiss31
Copy link
Copy Markdown
Contributor Author

Friendly bump @jklymak

Comment thread galleries/examples/subplots_axes_and_figures/secondary_axis.py Outdated
Comment thread galleries/examples/subplots_axes_and_figures/secondary_axis.py Outdated
secax = ax.secondary_xaxis('top', functions=(forward, inverse))
secax.xaxis.set_minor_locator(AutoMinorLocator())
secax.set_xlabel('$X_{other}$')
secax.set_xticks([10, 20, 40, 60, 80, 100])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: One could consider using the square numbers to make the relation even more obvious

Suggested change
secax.set_xticks([10, 20, 40, 60, 80, 100])
secax.set_xticks([4, 16, 36, 64, 100])

On the downside, this is proably slightly less "realistic", i.e. you would likely not find such tick positions in actual diagrams. Choose yourself, what you think is best.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I might prefer the way it is now? Just since it (maybe) more closely corresponds to what you'd have in a real plot

dkweiss31 and others added 2 commits November 20, 2024 14:10
explicitly label x2 = x1**2

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
simplify interpolation

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Comment thread galleries/examples/subplots_axes_and_figures/secondary_axis.py Outdated
Kill unhelpful comment

Co-authored-by: Jody Klymak <jklymak@gmail.com>
@timhoffm timhoffm added this to the v3.10.0 milestone Nov 21, 2024
@timhoffm timhoffm merged commit dcce480 into matplotlib:main Nov 21, 2024
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Nov 21, 2024
rcomer added a commit that referenced this pull request Nov 21, 2024
…073-on-v3.10.x

Backport PR #29073 on branch v3.10.x (Update secondary_axis tutorial)
ksunden pushed a commit to ksunden/matplotlib that referenced this pull request Nov 22, 2024
@melissawm melissawm moved this from Waiting for author to Merged in First Time Contributors Mar 6, 2026
@QuLogic QuLogic mentioned this pull request Jun 4, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: examples files in galleries/examples

Projects

Development

Successfully merging this pull request may close these issues.

[Bug]: secondary_xaxis produces ticks at incorrect locations

4 participants