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

Commit6e95994

Browse files
G26karthiktimhoffmjklymak
authored
DOC: Add note about linear colorbar scale option for TwoSlopeNorm (#30639)
* DOC: Add note about linear colorbar scale option for TwoSlopeNormAddresses#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.* FIX: Apply pre-commit fixes (end-of-file and line endings)* FIX: Use proper reStructuredText markup for inline code and class references* DOC: Add visual example comparing scaled vs linear colorbar for TwoSlopeNormReplace 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.* DOC: Refine TwoSlopeNorm colorbar documentation per maintainer feedback- 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* FIX: Add proper reStructuredText markup for code references- Add backticks around .TwoSlopeNorm class reference- Use double backticks for cb.ax.set_yscale('linear') code snippet- Fixes documentation build errors* Update galleries/users_explain/colors/colormapnorms.pyCo-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>* DOC: Address jklymak review feedback on colorbar explanation- 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: Resolve linting errors- 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.* FIX: Remove square brackets from np.arange in set_ticks callsThe 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.* Update galleries/users_explain/colors/colormapnorms.pyCo-authored-by: Jody Klymak <jklymak@gmail.com>* FIX: Remove extra blank line before section markerPrecommit linter expects only one blank line before # %% markers.* FIX: Ensure file ends with single newlineThe end-of-file-fixer precommit hook requires files to endwith exactly one newline, not multiple.* Update galleries/users_explain/colors/colormapnorms.pyCo-authored-by: Jody Klymak <jklymak@gmail.com>* Refactor TwoSlopeNorm colorbar example to use loop- 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* Fix linting errors: line length and inline comment spacing- 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---------Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>Co-authored-by: Jody Klymak <jklymak@gmail.com>
1 parentf380a44 commit6e95994

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎galleries/users_explain/colors/colormapnorms.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,32 @@
281281
cb.set_ticks([-500,0,1000,2000,3000,4000])
282282
plt.show()
283283

284+
# %%
285+
# Using a linear scale on the colormap
286+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287+
#
288+
# By default, colorbars adopt the same axis scaling as their associated norm.
289+
# For example, for a `.TwoSlopeNorm`, colormap segments are distributed
290+
# linearly and the colorbar ticks positions are spaced non-linearly (as above,
291+
# and the left-hand colorbar below). To make the tick spacing linear instead,
292+
# you can change the scale by calling ``cb.ax.set_yscale('linear')``, as shown
293+
# in the right-hand colorbar below. The ticks will then be evenly spaced, the
294+
# colormap will appear compressed in the smaller of the two slope regions.
295+
296+
fig, (ax1,ax2)=plt.subplots(1,2,figsize=(10,4))
297+
divnorm=colors.TwoSlopeNorm(vmin=-500.,vcenter=0,vmax=4000)
298+
299+
forax,titleinzip([ax1,ax2],
300+
['Default: Scaled colorbar','Linear colorbar spacing']):
301+
pcm=ax.pcolormesh(longitude,latitude,topo,rasterized=True,norm=divnorm,
302+
cmap=terrain_map,shading='auto')
303+
ax.set_aspect(1/np.cos(np.deg2rad(49)))
304+
ax.set_title(title)
305+
cb=fig.colorbar(pcm,ax=ax,shrink=0.6)
306+
cb.set_ticks(np.arange(-500,4001,500))
307+
308+
# Set linear scale for the right colorbar
309+
cb.ax.set_yscale('linear')
284310

285311
# %%
286312
# FuncNorm: Arbitrary function normalization
@@ -290,6 +316,7 @@
290316
# `~.colors.FuncNorm` to define your own. Note that this example is the same
291317
# as `~.colors.PowerNorm` with a power of 0.5:
292318

319+
293320
def_forward(x):
294321
returnnp.sqrt(x)
295322

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp