8000 New Colormaps to docs by mdboom · Pull Request #5284 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

New Colormaps to docs #5284

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 21, 2015
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add new colormaps to lightness
Also partly pep8 and make the figure a bit smaller
  • Loading branch information
jenshnielsen committed Aug 19, 2015
commit 4bc613f447653ec816f8154fbdffad27d610f46d
57 changes: 35 additions & 22 deletions doc/users/plotting/colormaps/lightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

import colorconv as color
#from skimage import color
# we are using a local copy of colorconv from scikit-image to reduce dependencies.
# 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.pyplot as plt
from matplotlib import cm
import matplotlib as mpl

mpl.rcParams.update({'font.size': 14})
mpl.rcParams['font.sans-serif'] = 'Arev Sans, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif'
mpl.rcParams.update({'font.size': 12})
mpl.rcParams['font.sans-serif'] = ('Arev Sans, Bitstream Vera Sans,'
'Lucida Grande, Verdana, Geneva, Lucid, Helvetica, Avant Garde, sans-serif')
Copy link
Member

Choose a reason for hiding this comment

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

Indent again.

mpl.rcParams['mathtext.fontset'] = 'custom'
mpl.rcParams['mathtext.cal'] = 'cursive'
mpl.rcParams['mathtext.rm'] = 'sans'
Expand All @@ -24,15 +26,17 @@
mpl.rcParams['mathtext.sf'] = 'sans'
mpl.rcParams['mathtext.fallback_to_cm'] = 'True'

# Have colormaps separated into categories: http://matplotlib.org/examples/color/colormaps_reference.html
# Have colormaps separated into categories:
# http://matplotlib.org/examples/color/colormaps_reference.html

cmaps = [('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']),
'gist_heat', 'gray', 'hot', 'inferno', 'magma',
'pink', 'plasma', 'spring', 'summer', 'viridis',
'winter']),
('Diverging', ['BrBG', 'bwr', 'coolwarm', 'PiYG', 'PRGn', 'PuOr',
'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral',
'seismic']),
Expand Down Expand Up @@ -60,14 +64,13 @@
dsub = 7
nsubplots = int(np.ceil(len(cmap_list)/float(dsub)))

fig = plt.figure(figsize=(11.5,4*nsubplots))
fig = plt.figure(figsize=(7,2.6*nsubplots))

for i, subplot in enumerate(range(nsubplots)):

locs = [] # locations for text labels

ax = fig.add_subplot(nsubplots, 1, i+1)
# pdb.set_trace()

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

Expand All @@ -79,10 +82,12 @@

# 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
# to make scatter markers change color along plot:
# http://stackoverflow.com/questions/8202605/matplotlib-scatterplot-colour-as-a-function-of-a-third-variable
Copy link
Member

Choose a reason for hiding this comment

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

It's (apparently) a little known secret that stackoverflow links can be shortened to http://stackoverflow.com/q/8202605

if cmap_category=='Sequential':
dc = 0.6 # spacing between colormaps
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r', s=300, linewidths=0.)
ax.scatter(x+j*dc, lab[0,::-1,0], c=x, cmap=cmap + '_r',
s=300, linewidths=0.)
if i==2:
ax.axis([-0.1,4.1,0,100])
else:
Expand All @@ -91,27 +96,34 @@

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.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,7.0,0,100])
locs.append(x[-1]+j*dc) # store locations for colormap labels
# 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.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,7.1,0,100])
locs.append(x[int(x.size/2.)]+j*dc) # store locations for colormap labels

# 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.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,6.3,0,100])
locs.append(x[int(x.size/2.)]+j*dc) # store locations for colormap labels
# 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.scatter(x+j*dc, lab[0,:,0], c=x, cmap=cmap,
s=300, linewidths=0.)
ax.axis([-0.1,6.1,0,100])
locs.append(x[int(x.size/2.)]+j*dc) # store locations for colormap labels
# 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')
Expand All @@ -123,8 +135,9 @@
for label in labels:
label.set_rotation(60)

ax.set_xlabel(cmap_category + ' colormaps', fontsize=22)
fig.text(-0.005, 0.55, 'Lightness $L^*$', fontsize=18, transform=fig.transFigure, rotation=90)
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)
fig.tight_layout(h_pad=0.05, pad=1.5)
plt.show()
0