Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
DOC: Add note about linear colorbar scale option for TwoSlopeNorm#30639
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
DOC: Add note about linear colorbar scale option for TwoSlopeNorm#30639
Conversation
Addressesmatplotlib#22197 by documenting the cb.ax.set_yscale('linear')workaround for users who prefer linear colorbar spacing instead ofthe default scaled spacing introduced in matplotlib 3.5.
Uh oh!
There was an error while loading.Please reload this page.
…opeNormReplace note with side-by-side example showing:- Left: Default scaled colorbar (centered at midpoint)- Right: Linear colorbar using cb.ax.set_yscale('linear')Addresses maintainer feedback from@jklymak to make the differencemore clear with a visual demonstration.
Uh oh!
There was an error while loading.Please reload this page.
- Change title from 'norms with a scale' to TwoSlopeNorm-specific- Clarify that colorbar is divided into two equal parts- Explain screen-space vs data range difference- Note that color-to-value mapping remains unchanged- Address review comments from@timhoffm
- Add backticks around .TwoSlopeNorm class reference- Use double backticks for cb.ax.set_yscale('linear') code snippet- Fixes documentation build errors
# `~.colors.FuncNorm` to define your own. Note that this example is the same | ||
# as `~.colors.PowerNorm` with a power of 0.5: | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Unrelated change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You didn't fix this
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think the wording could be clearer. Also please avoid the term "screen space". Screen space is completely virtual.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fig, (ax1,ax2)=plt.subplots(1,2,figsize=(10,4)) | ||
# Left plot: Default scaled colorbar (centered at midpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Most of this is repeated. I'd just put in a loop, and act on the last colorbar created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you are going to resolve a suggestion without taking it, it helps to explain why you ignored it.
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
- Rewrite explanation to avoid 'screen space' term per jklymak- Clarify that colorbars adopt their norm's scaling by default- Better explain TwoSlopeNorm splits colormap evenly between halves- Change tick specification to use np.arange for clarity- Update both cb1 and cb2 to use np.arange(-500, 4001, 500)Addresses@jklymak review comments
- Fix E501: Break long line (line 289) to stay under 88 character limit- Fix E302: Add missing blank line before function definitionAll ruff checks now pass.
Thank you both@timhoffm and@jklymak for your thorough reviews and excellent suggestions! 🙏 I've addressed all the feedback: @timhoffm's suggestions: @jklymak's suggestions: The documentation now provides clear, specific guidance with better examples. All CI checks should pass now. Thank you for helping improve this! 🎉 |
The set_ticks() method expects a 1D array with shape (N,), but wrappingnp.arange() in square brackets creates a list containing an array withshape (1, N). This fixes the ValueError by passing the array directly.
Co-authored-by: Jody Klymak <jklymak@gmail.com>
Precommit linter expects only one blank line before # %% markers.
The end-of-file-fixer precommit hook requires files to endwith exactly one newline, not multiple.
# `~.colors.FuncNorm` to define your own. Note that this example is the same | ||
# as `~.colors.PowerNorm` with a power of 0.5: | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You didn't fix this
fig, (ax1,ax2)=plt.subplots(1,2,figsize=(10,4)) | ||
# Left plot: Default scaled colorbar (centered at midpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you are going to resolve a suggestion without taking it, it helps to explain why you ignored it.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Jody Klymak <jklymak@gmail.com>
- Replace repeated code blocks with a loop as suggested by jklymak- Iterate over both axes with corresponding titles- Act on the last colorbar (cb) to set linear scale for right plot- Reduces code duplication and improves maintainability
Hi@jklymak, You're absolutely right, and I apologize for the confusion. I initially marked the conversation as resolved after addressing the grammar suggestion without implementing the loop refactoring you requested. I've now refactored the code to use a loop as you suggested in commitc8a0930. The changes include:
The refactored code is much cleaner and more maintainable. Thank you for pushing me to make this improvement—it's definitely better this way! Changes:
Thank you for your patience and detailed feedback! |
- Wrap long comment lines to stay within 88 character limit- Split zip() arguments across lines for better readability- Add blank line before section marker- All ruff checks now pass
jklymak left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good. ~But I'm removing your extra carriage return. ~
6e95994
intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
Appreciate your thorough review and for merging this in,@jklymak. I’ll make sure to avoid those extra carriage returns next time. |
Hi! I really enjoyed contributing to this repo and plan to do more in the future. If you could add the hacktoberfest-accepted label to this PR, it’d help me a lot. Thank you! 🙏 |
Fixes#22197
Summary
This PR adds a documentation note to the Colormap Normalization tutorial explaining how users can restore the pre-3.5 linear colorbar spacing for
TwoSlopeNorm
and other norms with a scale.Changes Made
TwoSlopeNorm
example ingalleries/users_explain/colors/colormapnorms.py
scale
use that scale by default (behavior introduced in matplotlib 3.5)cb.ax.set_yscale('linear')
workaround for users who prefer linear spacingContext
Since matplotlib 3.5, colorbars for norms with a scale (like
TwoSlopeNorm
) display the scale in the colorbar itself, which can appear non-linear. While this is consistent with other scaled norms likeLogNorm
, many users expect or prefer the linear spacing behavior from versions before 3.5.This note provides clear guidance on how to achieve linear colorbar spacing when desired, addressing a common user question documented in issue#22197.
Testing
TwoSlopeNorm
example is appropriate