In [1]:
import numpy as np
from lets_plot import *
In [2]:
LetsPlot.setup_html()

Setting Theme Parameters Via Sum In set_theme()

In [3]:
LetsPlot.set_theme(theme_bw() 
                   + flavor_darcula() 
                   + theme(panel_background=element_rect(fill='yellow')))
In [4]:
data = {'name': ['pen', 'brush', 'paper'],
        'slice': [1, 3, 3]}
ggplot(data) + \
    geom_pie(aes(fill='name', slice='slice'),
             stat='identity', color='pen',
             tooltips='none', labels=layer_labels().line('@name')) + \
    scale_fill_manual(['pen', 'brush', 'paper'])
Out[4]:

The Last Theme Overwrites Previous Theme Settings

In [5]:
LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) 
                   + theme_bw() 
                   + flavor_darcula())
In [6]:
data = {'name': ['pen', 'brush', 'paper'],
        'slice': [1, 3, 3]}
ggplot(data) + \
    geom_pie(aes(fill='name', slice='slice'),
             stat='identity', color='pen',
             tooltips='none', labels=layer_labels().line('@name')) + \
    scale_fill_manual(['pen', 'brush', 'paper'])
Out[6]:

The previous flavors are overwritten by the last flavor.

In [7]:
LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) 
                   + theme_bw() 
                   + flavor_darcula() 
                   + flavor_high_contrast_light())
In [8]:
data = {'name': ['pen', 'brush', 'paper'],
        'slice': [1, 3, 3]}
ggplot(data) + \
    geom_pie(aes(fill='name', slice='slice'),
             stat='identity', color='pen',
             tooltips='none', labels=layer_labels().line('@name')) + \
    scale_fill_manual(['pen', 'brush', 'paper'])
Out[8]:

Overwriting of Local Theme

In [9]:
data = {'name': ['pen', 'brush', 'paper'],
        'slice': [1, 3, 3]}
ggplot(data) + \
    geom_pie(aes(fill='name', slice='slice'),
             stat='identity', color='pen',
             tooltips='none', labels=layer_labels().line('@name')) + \
    scale_fill_manual(['pen', 'brush', 'paper']) +\
    theme(panel_background=element_rect(fill='yellow')) +\
    theme_classic() +\
    flavor_darcula() +\
    flavor_high_contrast_light()
Out[9]:

gggrid() and GGbunch()

In [10]:
LetsPlot.set_theme(theme_bw() 
                   + flavor_darcula() 
                   + theme(panel_background=element_rect(fill='yellow')))
In [11]:
np.random.seed(42)
n = 100
x = np.arange(n)
y = np.random.normal(size=n)
w, h = 200, 150
In [12]:
p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h)
plot_list=[
    gggrid([p+geom_point(), p+geom_histogram(bins=3)]),
    p+geom_line()
]
gggrid(plot_list, ncol=1) + ggsize(400, 300)
Out[12]:
In [13]:
p = ggplot({'x': x, 'y': y}, aes(x='x', y='y')) + ggsize(w, h)
bunch = GGBunch()
bunch.add_plot(p + geom_point(), 0, 0)
bunch.add_plot(p + geom_histogram(bins=3), w, 0)
bunch.add_plot(p + geom_line(), 0, h, 2*w, h)
bunch.show()

Wrong Type Exception

In [14]:
LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) 
                   + theme_bw() 
                   + flavor_darcula() 
                   + flavor_high_contrast_light()
                   + geom_point())
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[14], line 1
----> 1 LetsPlot.set_theme(theme(panel_background=element_rect(fill='yellow')) 
      2                    + theme_bw() 
      3                    + flavor_darcula() 
      4                    + flavor_high_contrast_light()
      5                    + geom_point())

File ~\AppData\Roaming\Python\Python310\site-packages\lets_plot\__init__.py:175, in LetsPlot.set_theme(cls, theme)
    165 """
    166 Set up global theme.
    167 
   (...)
    172 
    173 """
    174 if theme.kind != 'theme' and not (theme.kind == 'feature-list' and all(f.kind == 'theme' for f in theme)):
--> 175     raise ValueError("Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported")
    177 _set_global_theme(theme)

ValueError: Only `theme(...)`, `theme_xxx()`, `flavor_xxx()`, or a sum of them are supported