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

[Example] Add workaround for tick_top and sharex compatibility (#30219)#30225

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

Open
nrnavaneet wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromnrnavaneet:fix/tick_top-sharex-compatibility

Conversation

nrnavaneet
Copy link

Closes#30219

This PR adds a new example script underexamples/statistics/ that demonstrates a practical workaround for usingtick_top() withsharex=True in a subplot grid.

Background

When using shared x-axes,tick_top() does not restore tick labels on the top row because shared axes suppress labels on all but the bottom subplot by default. This results in unintuitive behaviour for users expecting top ticks on the uppermost axes.

What This Example Shows

This example:

  • Usestick_params(top=True, labeltop=True, bottom=False, labelbottom=False) on the top row,
  • Suppresses bottom ticks and labels to avoid overlap,
  • Appliesax.label_outer() to hide redundant ticks in the interior,
  • Demonstrates clean placement of x-axis labels on top for shared subplots.

This provides a clean, idiomatic alternative for achieving the intended visual layout.

Tested

  • Verified locally using an editable Matplotlib install.
  • Pre-commit hooks (ruff, codespell, etc.) all pass for this file.

@nrnavaneet
Copy link
Author

The failures appear unrelated to this PR, which only adds a new example script. Let me know if you’d like me to rebase or adjust anything!

@oscargus
Copy link
Member

Thanks for working on this! However, it does not show up in the documentation:https://output.circle-artifacts.com/output/job/f028b096-7bb3-4c19-86e1-26b205c9a66e/artifacts/0/doc/build/html/gallery/statistics/index.html

The reason is that there is no title of the example. Please see some of the other examples how to do that.

Also, it would be good if there was a bit context about what this example is showing. Something like "Combining YYY with ZZZ is a common pitfall and this example illustrates how one can work around that".

@nrnavaneet
Copy link
Author

Thanks for the helpful feedback!

I’ve added a title and a short docstring at the top of the example to ensure it shows up in the gallery. The description also now explains the context specifically how tick_top() behaves unexpectedly with sharex=True, and how this example provides a workaround using tick_params() and label_outer().

@timhoffm
Copy link
Member

Thanks for your willingness to contribute! However, I don't think this is going the right direction. First, the current best solution would be#30219 (comment). Second, and more importantly, the discussion in#30219 is going into the direction of enhancinglabel_outer() which then will canoncially work and doesn't need a separate "workaround example".

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Bug]: tick_top and sharex do not work together
3 participants
@nrnavaneet@oscargus@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp