#!/usr/bin/env python # coding: utf-8 # 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']) # ### 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']) # 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']) # ### 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() # ### `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) # 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())