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

Skip to content

Commit 72f88ae

Browse files
committed
Move colormaps to their respective tutorial sections.
It is strange to have them all at the end "in" the Miscellaneous section. And when sphinx-gallery sees multiple figures together, it makes those into a "list" at half size, which makes them much too small in the new theme.
1 parent b7d0591 commit 72f88ae

1 file changed

Lines changed: 58 additions & 53 deletions

File tree

tutorials/colors/colormaps.py

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
is from [IBM]_.
4848
4949
50+
.. _color-colormaps_reference:
51+
5052
Classes of colormaps
5153
====================
5254
@@ -82,8 +84,39 @@
8284
from colorspacious import cspace_converter
8385

8486

87+
###############################################################################
88+
#
89+
# First, we'll show the range of each colormap. Note that some seem
90+
# to change more "quickly" than others.
91+
8592
cmaps = {}
8693

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+
87120
###############################################################################
88121
# Sequential
89122
# ----------
@@ -96,13 +129,15 @@
96129
# amongst the colormaps: some are approximately linear in :math:`L^*` and others
97130
# are more curved.
98131

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+
###############################################################################
101136

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'])
106141

107142
###############################################################################
108143
# Sequential2
@@ -116,10 +151,10 @@
116151
# banding of the data in those values in the colormap (see [mycarta-banding]_ for
117152
# an excellent example of this).
118153

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'])
123158

124159
###############################################################################
125160
# Diverging
@@ -132,9 +167,9 @@
132167
# measures, BrBG and RdBu are good options. coolwarm is a good option, but it
133168
# doesn't span a wide range of :math:`L^*` values (see grayscale section below).
134169

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'])
138173

139174
###############################################################################
140175
# Cyclic
@@ -154,7 +189,7 @@
154189
# for viewers to see perceptually. See an extension on this idea at
155190
# [mycarta-jet]_.
156191

157-
cmaps['Cyclic'] = ['twilight', 'twilight_shifted', 'hsv']
192+
plot_color_gradients('Cyclic', ['twilight', 'twilight_shifted', 'hsv'])
158193

159194
###############################################################################
160195
# Qualitative
@@ -165,9 +200,10 @@
165200
# the place throughout the colormap, and are clearly not monotonically increasing.
166201
# These would not be good options for use as perceptual colormaps.
167202

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'])
171207

172208
###############################################################################
173209
# Miscellaneous
@@ -189,43 +225,12 @@
189225
# poor choice for representing data for viewers to see perceptually. See an
190226
# extension on this idea at [mycarta-jet]_ and [turbo]_.
191227

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']
197228

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'])
229234

230235
plt.show()
231236

0 commit comments

Comments
 (0)