|
47 | 47 | is from [IBM]_.
|
48 | 48 |
|
49 | 49 |
|
| 50 | +.. _color-colormaps_reference: |
| 51 | +
|
50 | 52 | Classes of colormaps
|
51 | 53 | ====================
|
52 | 54 |
|
|
82 | 84 | from colorspacious import cspace_converter
|
83 | 85 |
|
84 | 86 |
|
| 87 | +############################################################################### |
| 88 | +# |
| 89 | +# First, we'll show the range of each colormap. Note that some seem |
| 90 | +# to change more "quickly" than others. |
| 91 | + |
85 | 92 | cmaps = {}
|
86 | 93 |
|
| 94 | +gradient = np.linspace(0, 1, 256) |
| 95 | +gradient = np.vstack((gradient, gradient)) |
| 96 | + |
| 97 | + |
| 98 | +def plot_color_gradients(category, cmap_list): |
| 99 | + # Create figure and adjust figure height to number of colormaps |
| 100 | + nrows = len(cmap_list) |
| 101 | + figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 |
| 102 | + fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh)) |
| 103 | + fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, |
| 104 | + left=0.2, right=0.99) |
| 105 | + axs[0].set_title(f'{category} colormaps', fontsize=14) |
| 106 | + |
| 107 | + for ax, name in zip(axs, cmap_list): |
| 108 | + ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
| 109 | + ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10, |
| 110 | + transform=ax.transAxes) |
| 111 | + |
| 112 | + # Turn off *all* ticks & spines, not just the ones with colormaps. |
| 113 | + for ax in axs: |
| 114 | + ax.set_axis_off() |
| 115 | + |
| 116 | + # Save colormap list for later. |
| 117 | + cmaps[category] = cmap_list |
| 118 | + |
| 119 | + |
87 | 120 | ###############################################################################
|
88 | 121 | # Sequential
|
89 | 122 | # ----------
|
|
96 | 129 | # amongst the colormaps: some are approximately linear in :math:`L^*` and others
|
97 | 130 | # are more curved.
|
98 | 131 |
|
99 |
| -cmaps['Perceptually Uniform Sequential'] = [ |
100 |
| - 'viridis', 'plasma', 'inferno', 'magma', 'cividis'] |
| 132 | +plot_color_gradients('Perceptually Uniform Sequential', |
| 133 | + ['viridis', 'plasma', 'inferno', 'magma', 'cividis']) |
| 134 | + |
| 135 | +############################################################################### |
101 | 136 |
|
102 |
| -cmaps['Sequential'] = [ |
103 |
| - 'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', |
104 |
| - 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', |
105 |
| - 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn'] |
| 137 | +plot_color_gradients('Sequential', |
| 138 | + ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', |
| 139 | + 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', |
| 140 | + 'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']) |
106 | 141 |
|
107 | 142 | ###############################################################################
|
108 | 143 | # Sequential2
|
|
116 | 151 | # banding of the data in those values in the colormap (see [mycarta-banding]_ for
|
117 | 152 | # an excellent example of this).
|
118 | 153 |
|
119 |
| -cmaps['Sequential (2)'] = [ |
120 |
| - 'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink', |
121 |
| - 'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia', |
122 |
| - 'hot', 'afmhot', 'gist_heat', 'copper'] |
| 154 | +plot_color_gradients('Sequential (2)', |
| 155 | + ['binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', |
| 156 | + 'pink', 'spring', 'summer', 'autumn', 'winter', 'cool', |
| 157 | + 'Wistia', 'hot', 'afmhot', 'gist_heat', 'copper']) |
123 | 158 |
|
124 | 159 | ###############################################################################
|
125 | 160 | # Diverging
|
|
132 | 167 | # measures, BrBG and RdBu are good options. coolwarm is a good option, but it
|
133 | 168 | # doesn't span a wide range of :math:`L^*` values (see grayscale section below).
|
134 | 169 |
|
135 |
| -cmaps['Diverging'] = [ |
136 |
| - 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', |
137 |
| - 'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic'] |
| 170 | +plot_color_gradients('Diverging', |
| 171 | + ['PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu', 'RdYlBu', |
| 172 | + 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']) |
138 | 173 |
|
139 | 174 | ###############################################################################
|
140 | 175 | # Cyclic
|
|
154 | 189 | # for viewers to see perceptually. See an extension on this idea at
|
155 | 190 | # [mycarta-jet]_.
|
156 | 191 |
|
157 |
| -cmaps['Cyclic'] = ['twilight', 'twilight_shifted', 'hsv'] |
| 192 | +plot_color_gradients('Cyclic', ['twilight', 'twilight_shifted', 'hsv']) |
158 | 193 |
|
159 | 194 | ###############################################################################
|
160 | 195 | # Qualitative
|
|
165 | 200 | # the place throughout the colormap, and are clearly not monotonically increasing.
|
166 | 201 | # These would not be good options for use as perceptual colormaps.
|
167 | 202 |
|
168 |
| -cmaps['Qualitative'] = ['Pastel1', 'Pastel2', 'Paired', 'Accent', |
169 |
| - 'Dark2', 'Set1', 'Set2', 'Set3', |
170 |
| - 'tab10', 'tab20', 'tab20b', 'tab20c'] |
| 203 | +plot_color_gradients('Qualitative', |
| 204 | + ['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2', |
| 205 | + 'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b', |
| 206 | + 'tab20c']) |
171 | 207 |
|
172 | 208 | ###############################################################################
|
173 | 209 | # Miscellaneous
|
|
189 | 225 | # poor choice for representing data for viewers to see perceptually. See an
|
190 | 226 | # extension on this idea at [mycarta-jet]_ and [turbo]_.
|
191 | 227 |
|
192 |
| -cmaps['Miscellaneous'] = [ |
193 |
| - 'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern', |
194 |
| - 'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', |
195 |
| - 'gist_rainbow', 'rainbow', 'jet', 'turbo', 'nipy_spectral', |
196 |
| - 'gist_ncar'] |
197 | 228 |
|
198 |
| -############################################################################### |
199 |
| -# .. _color-colormaps_reference: |
200 |
| -# |
201 |
| -# First, we'll show the range of each colormap. Note that some seem |
202 |
| -# to change more "quickly" than others. |
203 |
| - |
204 |
| -gradient = np.linspace(0, 1, 256) |
205 |
| -gradient = np.vstack((gradient, gradient)) |
206 |
| - |
207 |
| - |
208 |
| -def plot_color_gradients(cmap_category, cmap_list): |
209 |
| - # Create figure and adjust figure height to number of colormaps |
210 |
| - nrows = len(cmap_list) |
211 |
| - figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22 |
212 |
| - fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh)) |
213 |
| - fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh, |
214 |
| - left=0.2, right=0.99) |
215 |
| - axs[0].set_title(cmap_category + ' colormaps', fontsize=14) |
216 |
| - |
217 |
| - for ax, name in zip(axs, cmap_list): |
218 |
| - ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name)) |
219 |
| - ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10, |
220 |
| - transform=ax.transAxes) |
221 |
| - |
222 |
| - # Turn off *all* ticks & spines, not just the ones with colormaps. |
223 |
| - for ax in axs: |
224 |
| - ax.set_axis_off() |
225 |
| - |
226 |
| - |
227 |
| -for cmap_category, cmap_list in cmaps.items(): |
228 |
| - plot_color_gradients(cmap_category, cmap_list) |
| 229 | +plot_color_gradients('Miscellaneous', |
| 230 | + ['flag', 'prism', 'ocean', 'gist_earth', 'terrain', |
| 231 | + 'gist_stern', 'gnuplot', 'gnuplot2', 'CMRmap', |
| 232 | + 'cubehelix', 'brg', 'gist_rainbow', 'rainbow', 'jet', |
| 233 | + 'turbo', 'nipy_spectral', 'gist_ncar']) |
229 | 234 |
|
230 | 235 | plt.show()
|
231 | 236 |
|
|
0 commit comments