Find Palettable online:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from palettable.colorbrewer.qualitative import Set1_9
Set1_9.name
'Set1'
Set1_9.type
'qualitative'
Set1_9.number
9
Set1_9.colors
[[228, 26, 28], [55, 126, 184], [77, 175, 74], [152, 78, 163], [255, 127, 0], [255, 255, 51], [166, 86, 40], [247, 129, 191], [153, 153, 153]]
Set1_9.hex_colors
['#E41A1C', '#377EB8', '#4DAF4A', '#984EA3', '#FF7F00', '#FFFF33', '#A65628', '#F781BF', '#999999']
Set1_9.mpl_colors
[(0.8941176470588236, 0.10196078431372549, 0.10980392156862745), (0.21568627450980393, 0.49411764705882355, 0.7215686274509804), (0.30196078431372547, 0.6862745098039216, 0.2901960784313726), (0.596078431372549, 0.3058823529411765, 0.6392156862745098), (1.0, 0.4980392156862745, 0.0), (1.0, 1.0, 0.2), (0.6509803921568628, 0.33725490196078434, 0.1568627450980392), (0.9686274509803922, 0.5058823529411764, 0.7490196078431373), (0.6, 0.6, 0.6)]
Set1_9.mpl_colormap
<matplotlib.colors.LinearSegmentedColormap at 0x106725d30>
# requires ipythonblocks
Set1_9.show_as_blocks()
Set1_9.show_continuous_image()
Set1_9.show_discrete_image()
Adapted from the example at http://matplotlib.org/examples/color/color_cycle_demo.html.
Use the .mpl_colors
attribute to change the color cycle used by matplotlib
when colors for plots are not specified.
from palettable.wesanderson import Aquatic1_5, Moonrise4_5
x = np.linspace(0, 2 * np.pi)
offsets = np.linspace(0, 2*np.pi, 4, endpoint=False)
# Create array with shifted-sine curve along each column
yy = np.transpose([np.sin(x + phi) for phi in offsets])
plt.rc('lines', linewidth=4)
plt.rc('axes', color_cycle=Aquatic1_5.mpl_colors)
fig, (ax0, ax1) = plt.subplots(nrows=2)
ax0.plot(yy)
ax0.set_title('Set default color cycle to Aquatic1_5')
ax1.set_color_cycle(Moonrise4_5.mpl_colors)
ax1.plot(yy)
ax1.set_title('Set axes color cycle to Moonrise4_5')
# Tweak spacing between subplots to prevent labels from overlapping
plt.subplots_adjust(hspace=0.3)
Adapted from http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html.
Use the .mpl_colormap
attribute any place you need a matplotlib colormap.
from palettable.colorbrewer.sequential import YlGnBu_9
from matplotlib.colors import LogNorm
#normal distribution center at x=0 and y=5
x = np.random.randn(100000)
y = np.random.randn(100000)+5
plt.hist2d(x, y, bins=40, norm=LogNorm(), cmap=YlGnBu_9.mpl_colormap)
plt.colorbar()
<matplotlib.colorbar.Colorbar at 0x107b0eda0>
Note that matplotlib already has colorbrewer palettes, as you can see at
http://matplotlib.org/examples/color/colormaps_reference.html.
Above I could have used cmap=plt.cm.YlGnBu
for the same affect.