Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DOC: Add missing cmaps to perception doc (fix for #8073) #8156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
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
40 changes: 21 additions & 19 deletions 40 doc/users/plotting/colormaps/colormaps.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
# Have colormaps separated into categories:
# http://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [('Perceptually Uniform Sequential',
['viridis', 'inferno', 'plasma', 'magma']),
('Sequential', ['Blues', 'BuGn', 'BuPu',
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
'copper', 'gist_heat', 'gray', 'hot',
'pink', 'spring', 'summer', 'winter']),
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
'seismic']),
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
'Pastel2', 'Set1', 'Set2', 'Set3']),
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
'brg', 'CMRmap', 'cubehelix',
'gnuplot', 'gnuplot2', 'gist_ncar',
'nipy_spectral', 'jet', 'rainbow',
'gist_rainbow', 'hsv', 'flag', 'prism'])]
cmaps = [('Perceptually Uniform Sequential', [
'viridis', 'plasma', 'inferno', 'magma']),
('Sequential', [
'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
('Sequential (2)', [
'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
'hot', 'afmhot', 'gist_heat', 'copper']),
('Diverging', [
'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
('Qualitative', [
'Pastel1', 'Pastel2', 'Paired', 'Accent',
'Dark2', 'Set1', 'Set2', 'Set3',
'tab10', 'tab20', 'tab20b', 'tab20c']),
('Miscellaneous', [
'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]
30 changes: 14 additions & 16 deletions 30 doc/users/plotting/colormaps/grayscale.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,37 @@
'''
Show what matplotlib colormaps look like in grayscale.
==================================
Grayscale version of the colormaps
==================================

Show what Matplotlib colormaps look like in grayscale.
Uses lightness L* as a proxy for grayscale value.
'''

from colormaps import cmaps

#from skimage import color
# we are using a local copy of colorconv from scikit-image to reduce dependencies.
# You should probably use the one from scikit-image in most cases.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cm
import matplotlib as mpl
from colorspacious import cspace_converter
from colormaps import cmaps # the colormaps, grouped by category

mpl.rcParams.update({'font.size': 14})


# indices to step through colormap
# Indices to step through colormap.
x = np.linspace(0.0, 1.0, 100)

# nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))


def plot_color_gradients(cmap_category, cmap_list):
nrows = len(cmap_list)
fig, axes = plt.subplots(nrows=nrows, ncols=2)
fig, axes = plt.subplots(nrows=len(cmap_list), ncols=2)
fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99,
wspace=0.05)
fig.suptitle(cmap_category + ' colormaps', fontsize=14, y=1.0, x=0.6)

for ax, name in zip(axes, cmap_list):

# Get rgb values for colormap
# Get RGB values for colormap.
rgb = cm.get_cmap(plt.get_cmap(name))(x)[np.newaxis,:,:3]

# Get colormap in CAM02-UCS colorspace. We want the lightness.
Expand All @@ -49,9 +47,9 @@ def plot_color_gradients(cmap_category, cmap_list):
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)

# Turn off *all* ticks & spines, not just the ones with colormaps.
for ax in axes:
ax[0].set_axis_off()
ax[1].set_axis_off()
for ax in axes.flat:
ax.set_axis_off()

plt.show()


Expand Down
150 changes: 65 additions & 85 deletions 150 doc/users/plotting/colormaps/lightness.py
Original file line number Diff line number Diff line change
@@ -1,120 +1,100 @@
'''
==========================
Lightness of the colormaps
==========================

For each colormap, plot the lightness parameter L* from CIELAB colorspace
along the y axis vs index through the colormap. Colormaps are examined in
categories as in the original matplotlib gallery of colormaps.
'''

from colormaps import cmaps
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cm
import matplotlib as mpl
from colorspacious import cspace_converter
from colormaps import cmaps # the colormaps, grouped by category

mpl.rcParams.update({'font.size': 12})

# indices to step through colormap
# Number of colormap per subplot for particular cmap categories
_DSUBS = {'Perceptually Uniform Sequential': 4, 'Sequential': 6,
'Sequential (2)': 6, 'Diverging': 6, 'Qualitative': 4,
'Miscellaneous': 6}

# Spacing between the colormaps of a subplot
Copy link
Member

@QuLogic QuLogic Mar 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to change the figure size like it used to be done. Now you get a different sized Axes and different number of ticks for each figure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand to which situation you are refering to: looking at blame on GH, the dc and dsub strategy is used since at least 3 years. I tried to not modify the spirit of the plots, but rather to refactor what could be, and to make the magic values a bit more uniform across all the different cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this comment probably shouldn't be here but on a subplots line. In any case, I missed the fact that you kept the changing figure size, so it should be the same as before.

But if the figure size changes based on the number of plots, then I don't understand why 00 and 05 have 3 y-ticks, but the others have 5.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not even notice the different amount of ticks ^^... If I had to guess, I would say that it may be an artifact from plt.tight_layout() that gives more or less place to the subplots depending on length of the x-tick labels.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be it. It would be nice if we didn't have to use tight_layout, but I guess then we'd need to know the size of the colormap labels first.

_DC = {'Perceptually Uniform Sequential': 1.4, 'Sequential': 0.7,
'Sequential (2)': 1.4, 'Diverging': 1.4, 'Qualitative': 1.4,
'Miscellaneous': 1.4}

# Indices to step through colormap
x = np.linspace(0.0, 1.0, 100)

# Do plot
for cmap_category, cmap_list in cmaps:

# Do subplots so that colormaps have enough space. 5 per subplot?
dsub = 5 # number of colormaps per subplot
if cmap_category == 'Diverging': # because has 12 colormaps
dsub = 6
elif cmap_category == 'Sequential (2)':
dsub = 6
elif cmap_category == 'Sequential':
dsub = 7
nsubplots = int(np.ceil(len(cmap_list)/float(dsub)))

fig = plt.figure(figsize=(7,2.6*nsubplots))
# Do subplots so that colormaps have enough space.
# Default is 6 colormaps per subplot.
dsub = _DSUBS.get(cmap_category, 6)
nsubplots = int(np.ceil(len(cmap_list) / float(dsub)))

for i, subplot in enumerate(range(nsubplots)):
# squeeze=False to handle similarly the case of a single subplot
fig, axes = plt.subplots(nrows=nsubplots, squeeze=False,
figsize=(7, 2.6*nsubplots))

locs = [] # locations for text labels
for i, ax in enumerate(axes.flat):

ax = fig.add_subplot(nsubplots, 1, i+1)
locs = [] # locations for text labels

for j, cmap in enumerate(cmap_list[i*dsub:(i+1)*dsub]):

# Get rgb values for colormap
rgb = cm.get_cmap(cmap)(x)[np.newaxis,:,:3]

# Get colormap in CAM02-UCS colorspace. We want the lightness.
# Get RGB values for colormap and convert the colormap in
# CAM02-UCS colorspace. lab[0, :, 0] is the lightness.
rgb = cm.get_cmap(cmap)(x)[np.newaxis, :, :3]
lab = cspace_converter("sRGB1", "CAM02-UCS")(rgb)

# Plot colormap L values
# Do separately for each category so each plot can be pretty
# to make scatter markers change color along plot:
# Plot colormap L values. Do separately for each category
# so each plot can be pretty. To make scatter markers change
# color along plot:
# http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
if cmap_category=='Perceptually Uniform Sequential':
dc = 1.15 # spacing between colormaps
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
if i==2:
ax.axis([-0.1,4.1,0,100])
else:
ax.axis([-0.1,4.7,0,100])
locs.append(x[-1]+j*dc) # store locations for colormap labels

elif cmap_category=='Sequential':
dc = 0.6 # spacing between colormaps

if cmap_category == 'Sequential':
# These colormaps all start at high lightness but we want them
# reversed to look nice in the plot, so reverse the order.
ax.scatter(x+j*dc, lab[0,::-1,0], c=x[::-1], cmap=cmap,
s=300, linewidths=0.)
if i==2:
ax.axis([-0.1,4.1,0,100])
else:
ax.axis([-0.1,4.7,0,100])
locs.append(x[-1]+j*dc) # store locations for colormap labels

elif cmap_category=='Sequential (2)':
dc = 1.15
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,7.0,0,100])
# store locations for colormap labels
locs.append(x[-1]+j*dc)

elif cmap_category=='Diverging':
dc = 1.2
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,7.1,0,100])
# store locations for colormap labels
locs.append(x[int(x.size/2.)]+j*dc)
elif cmap_category=='Qualitative':
dc = 1.3
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,6.3,0,100])
# store locations for colormap labels
locs.append(x[int(x.size/2.)]+j*dc)

elif cmap_category=='Miscellaneous':
dc = 1.25
ax.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,6.1,0,100])
# store locations for colormap labels
locs.append(x[int(x.size/2.)]+j*dc)

# Set up labels for colormaps
ax.xaxis.set_ticks_position('top')
ticker = mpl.ticker.FixedLocator(locs)
ax.xaxis.set_major_locator(ticker)
formatter = mpl.ticker.FixedFormatter(cmap_list[i*dsub:(i+1)*dsub])
ax.xaxis.set_major_formatter(formatter)
labels = ax.get_xticklabels()
for label in labels:
label.set_rotation(60)
y_ = lab[0, ::-1, 0]
c_ = x[::-1]
else:
y_ = lab[0, :, 0]
c_ = x

dc = _DC.get(cmap_category, 1.4) # cmaps horizontal spacing
ax.scatter(x + j*dc, y_, c=c_, cmap=cmap, s=300, linewidths=0.0)

# Store locations for colormap labels
if cmap_category in ('Perceptually Uniform Sequential',
'Sequential'):
locs.append(x[-1] + j*dc)
elif cmap_category in ('Diverging', 'Qualitative',
'Miscellaneous', 'Sequential (2)'):
locs.append(x[int(x.size/2.)] + j*dc)

# Set up the axis limits:
# * the 1st subplot is used as a reference for the x-axis limits
# * lightness values goes from 0 to 100 (y-axis limits)
ax.set_xlim(axes[0, 0].get_xlim())
ax.set_ylim(0.0, 100.0)

# Set up labels for colormaps
ax.xaxis.set_ticks_position('top')
ticker = mpl.ticker.FixedLocator(locs)
ax.xaxis.set_major_locator(ticker)
formatter = mpl.ticker.FixedFormatter(cmap_list[i*dsub:(i+1)*dsub])
ax.xaxis.set_major_formatter(formatter)
ax.xaxis.set_tick_params(rotation=50)

ax.set_xlabel(cmap_category + ' colormaps', fontsize=14)
fig.text(0.0, 0.55, 'Lightness $L^*$', fontsize=12,
transform=fig.transFigure, rotation=90)

fig.tight_layout(h_pad=0.05, pad=1.5)
fig.tight_layout(h_pad=0.0, pad=1.5)
plt.show()
41 changes: 21 additions & 20 deletions 41 examples/color/colormaps_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,27 @@

# Have colormaps separated into categories:
# http://matplotlib.org/examples/color/colormaps_reference.html
cmaps = [('Perceptually Uniform Sequential',
['viridis', 'inferno', 'plasma', 'magma']),
('Sequential', ['Blues', 'BuGn', 'BuPu',
'GnBu', 'Greens', 'Greys', 'Oranges', 'OrRd',
'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'RdPu',
'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd']),
('Sequential (2)', ['afmhot', 'autumn', 'bone', 'cool',
'copper', 'gist_heat', 'gray', 'hot',
'pink', 'spring', 'summer', 'winter']),
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
'seismic']),
('Qualitative', ['Accent', 'Dark2', 'Paired', 'Pastel1',
'Pastel2', 'Set1', 'Set2', 'Set3', 'tab10',
'tab20', 'tab20b', 'tab20c']),
('Miscellaneous', ['gist_earth', 'terrain', 'ocean', 'gist_stern',
'brg', 'CMRmap', 'cubehelix',
'gnuplot', 'gnuplot2', 'gist_ncar',
'nipy_spectral', 'jet', 'rainbow',
'gist_rainbow', 'hsv', 'flag', 'prism'])]
cmaps = [('Perceptually Uniform Sequential', [
'viridis', 'plasma', 'inferno', 'magma']),
('Sequential', [
'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
('Sequential (2)', [
'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
'hot', 'afmhot', 'gist_heat', 'copper']),
('Diverging', [
'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
('Qualitative', [
'Pastel1', 'Pastel2', 'Paired', 'Accent',
'Dark2', 'Set1', 'Set2', 'Set3',
'tab10', 'tab20', 'tab20b', 'tab20c']),
('Miscellaneous', [
'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]


nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.