#!/usr/bin/env python # coding: utf-8 # # Palettable # Find Palettable online: # # - Docs: https://jiffyclub.github.io/palettable/ # - GitHub: https://github.com/jiffyclub/palettable # - PyPI: https://pypi.python.org/pypi/palettable/ # In[2]: get_ipython().run_line_magic('matplotlib', 'inline') # In[3]: import matplotlib.pyplot as plt import numpy as np # # Palettable API # In[4]: from palettable.colorbrewer.qualitative import Set1_9 # In[5]: Set1_9.name # In[6]: Set1_9.type # In[7]: Set1_9.number # In[8]: Set1_9.colors # In[9]: Set1_9.hex_colors # In[10]: Set1_9.mpl_colors # In[11]: Set1_9.mpl_colormap # In[12]: # requires ipythonblocks Set1_9.show_as_blocks() # In[13]: Set1_9.show_continuous_image() # In[14]: Set1_9.show_discrete_image() # # Setting the matplotlib Color Cycle # 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) # # Using a Continuous Palette # 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() # 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[ ]: