Download notebook (.ipynb)

New Scale Functions with Parameter aesthetic#

  • scale_identity(aesthetic, *, ...)

  • scale_manual(aesthetic, values, *, ...)

  • scale_continuous(aesthetic, *, ...)

  • scale_gradient(aesthetic, *, ...)

  • scale_gradient2(aesthetic, *, ...)

  • scale_gradientn(aesthetic, *, ...)

  • scale_hue(aesthetic, *, ...)

  • scale_discrete(aesthetic, *, ...)

  • scale_grey(aesthetic, *, ...)

  • scale_brewer(aesthetic, *, ...)

  • scale_viridis(aesthetic, *, ...)

  • scale_cmapmpl(aesthetic, *, ...)

Comparing to familiar “scale” functions like scale_color_gradient() etc., the new set of functions adds more flexibility by allowing specifying an aesthetic or a list of aesthetics the scale is working with.

For example, you can use just one function call to setup the same color palette for both, stroke and fill colors on plot:

scale_brewer(['color', 'fill'], palette='Set2')

import pandas as pd

from lets_plot import *
LetsPlot.setup_html()
mpg_df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg.csv")

1. Plot with Default Colors#

p = ggplot(mpg_df, aes(as_discrete('drv', order=-1), 'hwy')) + \
    geom_violin(aes(color='drv', fill='drv'), alpha=.5, size=2)
p

2. Setup a Brewer Palette#

2.1. Old School: for Each Aesthetic Separately#

p + scale_color_brewer(palette='Set2') + scale_fill_brewer(palette='Set2')

2.2. New: for Both Aesthetics at Once#

p + scale_brewer(['color', 'fill'], palette='Set2')