Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Modernize Colorbar Tick Labelling example #26255

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

StefRe
Copy link
Contributor

@StefRe StefRe commented Jul 4, 2023

PR summary

  • use colorbar.set_ticks instead of colorbar.ax.set_[x|y]ticklabels whose usage is discouraged
  • now that we don't have to handle vertical and horizontal colorbars differently we can instead show different ways to achieve the same and show additional tweaks like labelling the colorbar extensions (strictly speaking the old labels >1 and <-1 were simply wrong for clipped data)
  • update numpy random number generation (see #25765#issuecomment-1529863936)
  • add admonition

The clause "Contributed by Scott Sinclair" was removed in the process as I think contributors can be looked up in git but I can of course add this phrase back if desired.

PR checklist

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

The must change or address are the comments having to do w/ our doc conventions, the rest are copy edits.

Comment on lines 8 to 11
Vertical colorbars have their y axis labelled, horizontal ones their x axis.
The ``ticks`` and ``format`` parameters can be used to set ticks and format
labels of these axes. For further adjustments, the ``yaxis`` or ``xaxis`` axes
of the colorbar can be retrieved using its ``ax`` property.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Vertical colorbars have their y axis labelled, horizontal ones their x axis.
The ``ticks`` and ``format`` parameters can be used to set ticks and format
labels of these axes. For further adjustments, the ``yaxis`` or ``xaxis`` axes
of the colorbar can be retrieved using its ``ax`` property.
Vertical colorbars have ticks, tick labels, and labels visible on the *y* axis, horizontal colorbars on the *x* axis. The ``ticks`` parameter can be used to set the ticks and the ``format`` parameter can be used to format the tick labels of the colorbar axes. For further adjustments, the ``yaxis`` or ``xaxis`` axes of the colorbar can be retrieved using its ``ax`` property.

Tried to make everything a little more explicit and unpacked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, much better now. I just inserted the word visible in

... can be used to format the tick labels of the visible colorbar axes.

to underline that you can use these parameters no matter what the colorbar orientation is, there is no need to resort to the specific x/y axis functions

- use colorbar.set_ticks instead of colorbar.ax.set_[x|y]ticklabels whose
  usage is discouraged
- now that we don't have to handle vertical and horizontal colorbars
  differently we can instead show different ways to achieve the same
  and show additional tweaks like labelling the colorbar extensions
  (strictly speaking the old labels >1 and <-1 were simply wrong for
  clipped data)
- update numpy random number generation
- add admonition
@StefRe StefRe force-pushed the doc/color_tick_labelling branch from ae9f762 to 1542cee Compare July 5, 2023 06:27
@StefRe
Copy link
Contributor Author

StefRe commented Jul 5, 2023

@story645 Thanks for the review. All done. The only annoying thing is that the isort commit hook insists in changing

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import numpy as np

into

import matplotlib.pyplot as plt
import numpy as np

import matplotlib.ticker as mticker 

(see also https://discourse.matplotlib.org/t/isort-run-as-commit-hook/23932)

Is this a bug in isort or am I missing something here?

@rcomer
Copy link
Member

rcomer commented Jul 5, 2023

I think this was a deliberate choice for the examples when we added the isort hook, see #25099 (comment).

@StefRe StefRe requested a review from story645 July 5, 2023 08:31
@story645 story645 added this to the v3.7-doc milestone Jul 5, 2023

# Fixing random state for reproducibility
np.random.seed(19680801)
rng = np.random.default_rng(seed=19680801)

# %%
# Make plot with vertical (default) colorbar
Copy link
Member

Choose a reason for hiding this comment

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

Final little nit that can also happen in follow up - how do you feel about making this and the horizontal note instead be subsection titles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd rather not make them be subsection titles as both vertical and horizontal colorbars work exactly the same way. Subsections would be appropriate if we had different cases to contrast, in my opinion.

Copy link
Member

Choose a reason for hiding this comment

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

I hear you, what I'm thinking of is that in the sidebar you can scan quickly to click to find your case. Also maybe that if what you want to highlight is that they're exactly the same, then I'd maybe do this as a side by side subplot so that I could stack the identical code next to each other...either way I'll merge this and push that off.

@story645 story645 merged commit 1cc50f6 into matplotlib:main Jul 5, 2023
@lumberbot-app
Copy link

lumberbot-app bot commented Jul 5, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 1cc50f659a3a488c6ef9a265448a48a99956f411
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #26255: DOC: Modernize Colorbar Tick Labelling example'
  1. Push to a named branch:
git push YOURFORK v3.7.x:auto-backport-of-pr-26255-on-v3.7.x
  1. Create a PR against branch v3.7.x, I would have named this PR:

"Backport PR #26255 on branch v3.7.x (DOC: Modernize Colorbar Tick Labelling example)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@lumberbot-app
Copy link

lumberbot-app bot commented Jul 5, 2023

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout v3.7.1-doc
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 1cc50f659a3a488c6ef9a265448a48a99956f411
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #26255: DOC: Modernize Colorbar Tick Labelling example'
  1. Push to a named branch:
git push YOURFORK v3.7.1-doc:auto-backport-of-pr-26255-on-v3.7.1-doc
  1. Create a PR against branch v3.7.1-doc, I would have named this PR:

"Backport PR #26255 on branch v3.7.1-doc (DOC: Modernize Colorbar Tick Labelling example)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

@QuLogic QuLogic modified the milestones: v3.7-doc, v3.8.0 Jul 5, 2023
@StefRe StefRe deleted the doc/color_tick_labelling branch July 5, 2023 18:59
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