-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
dstansby
merged 6 commits into
matplotlib:master
from
afvincent:add_missing_cmaps_to_perception_doc
Apr 2, 2017
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c847be2
Add missing colormaps to the relevant doc pages
afvincent 38526b4
tweak cmap list order for a better fit of "Wistia"
afvincent a769e5b
Cleaning up 'grayscale.py' script
afvincent 0c9a280
Overhaul and refactoring of the 'lightness.py' script
afvincent 3c29961
Reordering the colormaps and add a few missing ones
afvincent e442647
Fix minor typo
afvincent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
_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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
anddsub
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.