Esempio n. 1
0
def set_color_palette(n=8, name = 'viridis'):
    """ 
    name: 
        husl - like a rainbow
        cubehelix - colorblind, black-white printing
    """
    
    if name == "husl":
        MM = color.LinearColormap('snsmap', color_palette("husl"))
        color.cycle_cmap(length = n, cmap = MM)

    elif name == 'cubehelix':
        MM = color.LinearColormap('snsmap', cubehelix_palette(n, start=.5, rot=-.75))
        color.cycle_cmap(length = n, cmap = MM)
        
    else:
        cmap = plt.get_cmap(name)
        cgen = (cmap(1.*i/n) for i in range(n))
        matplotlib.rc('axes', prop_cycle = cycler('color', cgen)) 
Esempio n. 2
0
def quick_colormap(rgb_list, name="name"):
    """Quickly make a colormap out of a few specified RGB(A) values that will be equally spaced along the colormap linearly.

    >>> cm = quick_colormap( ( (60/255.0,0,60/255.0), (1.0,0,1.0), ) , name = "dark to light purple")
    >>> cm(0.0)
    (0.23529411764705882, 0.0, 0.23529411764705882, 1.0)
    >>> cm(1.0)
    (1.0, 0.0, 1.0, 1.0)
    >>> isinstance(cm, LinearColormap)
    True

    """

    return C.LinearColormap(name, rgb_list)
Esempio n. 3
0

# In[5]:

monthly.plot(kind='area')


# In[6]:

from mpltools import style
style.use('ggplot')


# In[9]:

print style.available


# In[11]:

#try making a colormap
from mpltools import color
tencolor = color.LinearColormap('tencolor', [(0.02, 0.2, 0.4, 1), (0.4, 0.0, 0.1, 1), (0.02, 0.4, 0.02, 1) ,(0.8, 0, 0,1), (0, 0.8, 0, 1), (0, 0, 0.8, 1), (0.4, 0.4, 0, 1), (0, 0.4, 0.4, 1), (0.4, 0, 0.4, 1), (0.3, 0,0,1)])
monthly.plot(kind='area', cmap=tencolor)


# In[ ]:



==============

This class simplifies the creation of Matplotlib colormaps. To specify
a colormap, you can just specify key colors in the colormap, and
``LinearColormap`` will distribute those colors evenly in the colormap and
linearly interpolate in-between. In the example below, specifying two colors
defines the minimum and maximum color values of the colormap.
"""
import numpy as np
import matplotlib.pyplot as plt

from mpltools import color

x, y, z = np.random.uniform(size=(3, 100))

white_red = color.LinearColormap('white_red', [(1, 1, 1), (0.8, 0, 0)])
plt.scatter(x, y, c=z, cmap=white_red, s=200)
"""
.. image:: PLOT2RST.current_figure

To get more complicated, use the ``index`` argument to specify where the color
values map to in the colormap. Here, we repeat an index to get a segmented
colormap. This colormap is uniformly blue below the midpoint and red above the
midpoint. Alpha values are maximum at the edges and minimum in the middle.
"""

bcr_rgba = [
    (0.02, 0.2, 0.4, 1),  # grayish blue, opaque
    (0.02, 0.2, 0.4, 0.3),  # grayish blue, transparent
    (0.4, 0.0, 0.1, 0.3),  # dark red, transparent
    (0.4, 0.0, 0.1, 1)