Skip to content

Tweak secondary_{x,y}axis docs.#31405

Merged
QuLogic merged 1 commit intomatplotlib:mainfrom
anntzer:saxd
Mar 28, 2026
Merged

Tweak secondary_{x,y}axis docs.#31405
QuLogic merged 1 commit intomatplotlib:mainfrom
anntzer:saxd

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Mar 27, 2026

Use a full sentence with a principal clause. Also, the data is not plotted on the x- or y-axis; it is the scale that is on the x- or y-axis.

PR summary

AI Disclosure

PR checklist

Copy link
Copy Markdown
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Small suggestion though I wonder if this is even an example or the by far predominant use

For example if we want to have a second scale for the data plotted on
the xaxis.
This axis can e.g. display a second x-scale for the data plotted on the Axes.
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.

Suggested change
This axis can e.g. display a second x-scale for the data plotted on the Axes.
This axis can, for example, display a second x-scale for the data plotted on the Axes.

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.

Given the discussion below, I reworded to "is typically used to...". Let me know if you want to stick to "for example".

For example if we want to have a second scale for the data plotted on
the yaxis.
This axis can e.g. display a second y-scale for the data plotted on the Axes.
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.

Suggested change
This axis can e.g. display a second y-scale for the data plotted on the Axes.
This axis can, for example, display a second y-scale for the data plotted on the Axes.

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Mar 27, 2026

I think this is the only use. The secondary axis is coupled to the primary axis through a functional relationship.

Side question: Is it ever intended to add data to the Axes created by secondary_xaxis? Likely not as the yticks are removed, so that we don't have a visual scale for that data. Also we don't have an example on using this.

The "Returns" section could be amended by something like

The returned Axes is overlaid on top of the original Axes and all components except for the complementary axis are hidden. You may modify the complementary axis, e.g. by setting ticks or an axis label. However, it is not designed to hold data.


On a general note, this concept is a bit of a crutch. It would be better to allow secondary Axis objects on Axes instead of creating a full separate Axes instance and hiding everything we don't need. But that'd be a substantial change which we are not going to make any time soon if ever. So the solution is here to stay. It's been marked as experimental since 3.1. I'm fine with keeping that on the basis that it's not a great design, but OTOH it's been around for a long time and we are not likely to change it, so we could as well remove the experimental status. There are about 3k usages (https://github.com/search?q=%2Fsecondary_%5Bxy%5Daxis%5C%28%2F+language%3APython+NOT+is%3Afork&type=code), so it's not too much but also not negligible, so that we may not want to break them even if we technically could due to the experimental status.

Use a full sentence with a principal clause.  Also, the data is not
plotted on the x- or y-axis; it is the scale that is on the x- or
y-axis.
@QuLogic QuLogic added this to the v3.11.0 milestone Mar 28, 2026
@QuLogic QuLogic merged commit 30c3d78 into matplotlib:main Mar 28, 2026
40 of 41 checks passed
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Mar 28, 2026
@anntzer anntzer deleted the saxd branch March 28, 2026 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants