Show Sidebar Hide Sidebar

Color scales in IPython notebook in Python

Color scales in IPython notebook.

colorlover

Color scales for IPython notebook
Install with pip, sudo pip install colorlover Code and documentation on Github
In [5]:
import colorlover as cl
from IPython.display import HTML
Display a single color scale
In [6]:
HTML(cl.to_html( cl.scales['3']['div']['RdYlBu'] ))
Out[6]:
Display many color scales
In [7]:
HTML(cl.to_html( cl.scales['11'] )) # All scales with 11 colors
Out[7]:

Qualitative

Paired
Set3

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy
Display sequential color scales (with 3 colors)
In [8]:
HTML(cl.to_html( cl.flipper()['seq']['3'] ))
Out[8]:
Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples
Scales are RGB by default...
In [9]:
ryb = cl.scales['3']['div']['RdYlBu']; ryb
Out[9]:
['rgb(252,141,89)', 'rgb(255,255,191)', 'rgb(145,191,219)']
But its easy to change to HSL...
In [10]:
cl.to_hsl( ryb )
Out[10]:
['hsl(19.0, 96.0%, 67.0%)',
 'hsl(60.0, 100.0%, 87.0%)',
 'hsl(203.0, 51.0%, 71.0%)']
Or tuples of RGB values
In [11]:
cl.to_numeric( ryb )
Out[11]:
[(252.0, 141.0, 89.0), (255.0, 255.0, 191.0), (145.0, 191.0, 219.0)]

Color interpolation

In [14]:
bupu = cl.scales['9']['seq']['BuPu']
HTML( cl.to_html(bupu) )
Out[14]:
In [15]:
bupu500 = cl.interp( bupu, 500 ) # Map color scale to 500 bins
HTML( cl.to_html( bupu500 ) )
Out[15]:

Creating plots

(pip install --upgrade plotly for latest Plotly package version)
In [16]:
import plotly.plotly as py
from plotly.graph_objs import *
import math

un='IPython.Demo'; k='1fw3zw2o13'; py.sign_in(un,k);

data = Data([ Scatter(
    x = [ i * 0.1 for i in range(500) ],
    y = [ math.sin(j * 0.1) for j in range(500) ],
    mode='markers',
    marker=Marker(color=bupu500,size=22.0,line=Line(color='black',width=2)),
    text = cl.to_rgb( bupu500 ),
    opacity = 0.7
)])
layout = Layout( showlegend=False, xaxis=XAxis(zeroline=False), yaxis=YAxis(zeroline=False) )
fig = Figure(data=data, layout=layout)
py.iplot(fig, filename='spectral_bubblechart')
Out[16]:

All colors

In [17]:
HTML(cl.to_html( cl.scales ))
Out[17]:

11 colors

Qualitative

Paired
Set3

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

10 colors

Qualitative

Paired
Set3

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

3 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

12 colors

Qualitative

Paired
Set3

5 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

4 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

7 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

6 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

9 colors

Qualitative

Paired
Pastel1
Set1
Set3

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

8 colors

Qualitative

Pastel2
Paired
Pastel1
Set1
Set2
Set3
Dark2
Accent

Diverging

RdYlBu
Spectral
RdYlGn
PiYG
PuOr
PRGn
BrBG
RdBu
RdGy

Sequential

Reds
YlOrRd
RdPu
YlOrBr
Greens
YlGnBu
GnBu
BuPu
Greys
Oranges
OrRd
BuGn
PuBu
PuRd
Blues
PuBuGn
YlGn
Purples

Color scales in cl.scales and much inspiration are from ColorBrewer

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to a Developer Support Plan.