Find Palettable online:
In [2]:
%matplotlib inline
In [3]:
import matplotlib.pyplot as plt
import numpy as np
In [4]:
from palettable.colorbrewer.qualitative import Set1_9
In [5]:
Set1_9.name
Out[5]:
In [6]:
Set1_9.type
Out[6]:
In [7]:
Set1_9.number
Out[7]:
In [8]:
Set1_9.colors
Out[8]:
In [9]:
Set1_9.hex_colors
Out[9]:
In [10]:
Set1_9.mpl_colors
Out[10]:
In [11]:
Set1_9.mpl_colormap
Out[11]:
In [12]:
# requires ipythonblocks
Set1_9.show_as_blocks()
In [13]:
Set1_9.show_continuous_image()
In [14]:
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.
In [3]:
from palettable.wesanderson import Aquatic1_5, Moonrise4_5
In [4]:
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.
In [5]:
from palettable.colorbrewer.sequential import YlGnBu_9
In [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()
Out[9]:
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.
In [ ]: