8000 Backport PR #21727 on branch v3.5.0-doc (Doc fix colormap inaccuracy) by meeseeksmachine · Pull Request #21731 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions tutorials/colors/colormap-manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ def plot_examples(colormaps):
plot_examples([viridis, newcmp])

##############################################################################
# We can easily reduce the dynamic range of a colormap; here we choose the
# middle 0.5 of the colormap. However, we need to interpolate from a larger
# colormap, otherwise the new colormap will have repeated values.

viridis_big = cm.get_cmap('viridis', 512)
newcmp = ListedColormap(viridis_big(np.linspace(0.25, 0.75, 256)))
# We can reduce the dynamic range of a colormap; here we choose the
# middle half of the colormap. Note, however, that because viridis is a
# listed colormap, we will end up with 128 discrete values instead of the 256
# values that were in the original colormap. This method does not interpolate
# in color-space to add new colors.

viridis_big = cm.get_cmap('viridis')
newcmp = ListedColormap(viridis_big(np.linspace(0.25, 0.75, 128)))
plot_examples([viridis, newcmp])

##############################################################################
Expand Down
0