From 303881de93cbdbb46d867586aee623f48305c845 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 23 Nov 2021 13:40:10 +0100 Subject: [PATCH] DOC: fix inaccuracy in colormap tutorial Co-authored-by: Greg Lucas --- tutorials/colors/colormap-manipulation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tutorials/colors/colormap-manipulation.py b/tutorials/colors/colormap-manipulation.py index 9c68dfb25b4b..bbd8cb8d2b2f 100644 --- a/tutorials/colors/colormap-manipulation.py +++ b/tutorials/colors/colormap-manipulation.py @@ -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]) ##############################################################################