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

Skip to content

Commit d6a5179

Browse files
committed
DOC: fix overinterp issue and modify intro para
1 parent f58f5f3 commit d6a5179

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

tutorials/colors/colormap-manipulation.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
Creating Colormaps in Matplotlib
44
********************************
55
6-
Matplotlib colormaps are implimented as a class, which makes them quite
7-
flexible, but opaque to users as to how to create and/or
8-
manipulate them. This opacity is not helped in the library by the fact that
9-
the named colormaps are accessed via `.matplotlib.cm.get_cmap` module, whereas
10-
the colormap class itself is defined in `.matplotlib.colors.Colormap`!
11-
12-
Fortunately, the way to create colormaps is quite straight forward, by creating
13-
an instance of class `.ListedColormap` using a Nx4 numpy array of values
14-
between 0 and 1 to represent the RGBA values of the colormap.
6+
Creating and manipulating colormaps in Matplotlib is quite straight-forward
7+
using the class `.ListedColormap` and a Nx4 numpy array of values
8+
between 0 and 1 to represent the RGBA values of the colormap. There
9+
is also a `.LinearSegmentedColormap` class that allows colormaps to be
10+
specified with far fewer anchor points defining segments, and linearly
11+
interpolating between the anchor points.
1512
1613
Getting colormaps and accessing their values
1714
============================================
@@ -93,11 +90,12 @@ def plot_examples(cms):
9390
plot_examples([viridis, newcmp])
9491

9592
##############################################################################
96-
# We can easily reduce the range of a colormap; here we choose the middle
97-
# 0.5 of the colormap.
93+
# We can easily reduce the dynamic range of a colormap; here we choose the
94+
# middle 0.5 of the colormap. However, we need to interpolate from a larger
95+
# colormap, otherwise the new colormap will have repeated values.
9896

99-
viridis = cm.get_cmap('viridis', 256)
100-
newcmp = ListedColormap(viridis(np.linspace(0.25, 0.75, 256)))
97+
viridisBig = cm.get_cmap('viridis', 512)
98+
newcmp = ListedColormap(viridisBig(np.linspace(0.25, 0.75, 256)))
10199
plot_examples([viridis, newcmp])
102100

103101
##############################################################################

0 commit comments

Comments
 (0)