Show Sidebar Hide Sidebar

Adding Colorscales (Using Colorlover) in Pandas

How to easily add colorscales to pandas dataframe using Colorlover and Plotly.

Adding Colorscales to Pandas DataFrames

Colorlover is a great library for easily accessing colorscales. We can use it to conveniently provide the colorscales for Plotly Charts! We will be using the cufflinks library, which binds Plotly directly to pandas dataframes.

To install Cufflinks:

$ pip install cufflinks

And Colorlover:

$ pip install colorlover

Using Colorlover to easily access colorscales:

In [3]:
import colorlover as cl
In [4]:
from IPython.display import HTML

For example, to access all the colorscales with 9 colors:

In [5]:
HTML(cl.to_html(cl.scales['9']))
Out[5]:

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
In [6]:
import cufflinks as cf
In [7]:
# Generate a sample dataset of 9 traces (lines)..
sample_data = cf.datagen.lines(5)

Plotting the data using Plotly:

In [8]:
sample_data.iplot(kind='scatter', filename='basic-cufflinks-example')
Out[8]:

Adding Colorscales using Colorlover:

In [9]:
color_scale_blues = cl.scales['5']['seq']['Blues']
In [10]:
sample_data.iplot(kind='scatter', colors=color_scale_blues, theme='pearl')
Out[10]:

A list of all the colorscales supported by colorlover is available here!

Still need help?
Contact Us

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