The viridis color maps are designed to be perceptually-uniform, both in regular form and also when converted to black-and-white.

More info: https://bids.github.io/colormap/

In [1]:
import pandas as pd
from lets_plot import *

LetsPlot.setup_html()
In [2]:
mpg = pd.read_csv ("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv")
mpg.head(3)
Out[2]:
miles per gallon number of cylinders engine displacement (cu. inches) engine horsepower vehicle weight (lbs.) time to accelerate (sec.) model year origin of car vehicle name
0 18.0 8 307.0 130 3504 12.0 70 US chevrolet chevelle malibu
1 15.0 8 350.0 165 3693 11.5 70 US buick skylark 320
2 18.0 8 318.0 150 3436 11.0 70 US plymouth satellite
In [3]:
def pair(p0, p1):
    bunch = GGBunch()
    bunch.add_plot(p0, x=0, y=0, width=500, height=300)
    bunch.add_plot(p1, x=500, y=0, width=500, height=300)
    return bunch
In [4]:
p_c = (ggplot(mpg) + 
 geom_point(aes("vehicle weight (lbs.)", "miles per gallon", color="miles per gallon"), size=7) + 
 ggtitle("Continuous data") + labs(color="MPG"))

p_d = (ggplot(mpg) + geom_bar(aes("origin of car", fill="origin of car")) +
 ggtitle("Discrete data") + labs(fill=""))

The "viridis" colormap is the default option.

Adjust scales with begin, end, alpha and direction parameters.

In [5]:
pair(p_c + scale_color_viridis(),
     p_c + scale_color_viridis(end=0.5))
Out[5]:
In [6]:
pair(p_d + scale_fill_viridis(),
     p_d + scale_fill_viridis(begin=0.3, end=0.8))
Out[6]:
In [7]:
pair(p_d + scale_fill_viridis(alpha=0.4),
     p_d + scale_fill_viridis(begin=0.3, end=0.8, direction=-1))
Out[7]:

Supported colormaps

Use the option parameter to select a colormap you like:

  • "magma" (or "A"),
  • "inferno" (or "B")
  • "plasma" (or "C")
  • "viridis" (or "D") - the default
  • "cividis" (or "E")
  • "turbo"
  • "twilight"

Magma

In [8]:
pair(p_c + scale_color_viridis(option="A"),
     p_d + scale_fill_viridis(option="magma"))
Out[8]:

Inferno

In [9]:
pair(p_c + scale_color_viridis(option="B"),
     p_d + scale_fill_viridis(option="inferno"))
Out[9]:

Plasma

In [10]:
pair(p_c + scale_color_viridis(option="C"),
     p_d + scale_fill_viridis(option="plasma"))
Out[10]:

Viridis

In [11]:
pair(p_c + scale_color_viridis(option="D"),
     p_d + scale_fill_viridis(option="viridis"))
Out[11]:

Cividis

In [12]:
pair(p_c + scale_color_viridis(option="E"),
     p_d + scale_fill_viridis(option="cividis"))
Out[12]:

Turbo

In [13]:
pair(p_c + scale_color_viridis(option="turbo", direction=-1),
     p_d + scale_fill_viridis(option="turbo"))
Out[13]:

Twilight

In [14]:
pair(p_c + scale_color_viridis(option="twilight"),
     p_d + scale_fill_viridis(option="twilight"))
Out[14]: