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")
mpg_df
Unnamed: 0 | manufacturer | model | displ | year | cyl | trans | drv | cty | hwy | fl | class | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | audi | a4 | 1.8 | 1999 | 4 | auto(l5) | f | 18 | 29 | p | compact |
1 | 2 | audi | a4 | 1.8 | 1999 | 4 | manual(m5) | f | 21 | 29 | p | compact |
2 | 3 | audi | a4 | 2.0 | 2008 | 4 | manual(m6) | f | 20 | 31 | p | compact |
3 | 4 | audi | a4 | 2.0 | 2008 | 4 | auto(av) | f | 21 | 30 | p | compact |
4 | 5 | audi | a4 | 2.8 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | compact |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
229 | 230 | volkswagen | passat | 2.0 | 2008 | 4 | auto(s6) | f | 19 | 28 | p | midsize |
230 | 231 | volkswagen | passat | 2.0 | 2008 | 4 | manual(m6) | f | 21 | 29 | p | midsize |
231 | 232 | volkswagen | passat | 2.8 | 1999 | 6 | auto(l5) | f | 16 | 26 | p | midsize |
232 | 233 | volkswagen | passat | 2.8 | 1999 | 6 | manual(m5) | f | 18 | 26 | p | midsize |
233 | 234 | volkswagen | passat | 3.6 | 2008 | 6 | auto(s6) | f | 17 | 26 | p | midsize |
234 rows × 12 columns
p = ggplot(mpg_df, aes("cty","hwy", color='drv')) + \
geom_point(tooltips=layer_tooltips().line('@manufacturer @model'))
p2 = p + facet_grid(y="drv")
w, h = 600, 400
def themeWithFlavor(plot, theme, title):
bunch = GGBunch()
bunch.add_plot(plot + theme + ggtitle(title), 0, 0, w, h)
bunch.add_plot(plot + theme + flavor_darcula()+ ggtitle("darcula"), w, 0, w, h)
bunch.add_plot(plot + theme + flavor_solarized_light()+ ggtitle("solarized_light"), 0, h, w, h)
bunch.add_plot(plot + theme + flavor_solarized_dark()+ ggtitle("solarized_dark"), w, h, w, h)
bunch.add_plot(plot + theme + flavor_high_contrast_light()+ ggtitle("high_contrast_light"), 0, h*2, w, h)
bunch.add_plot(plot + theme + flavor_high_contrast_dark()+ ggtitle("high_contrast_dark"), w, h*2, w, h)
bunch.show()
themeWithFlavor(p, theme_minimal2(), "minimal2")
themeWithFlavor(p2, theme_minimal2(), "minimal2 + facet_grid")
themeWithFlavor(p, theme_minimal(), "minimal")
themeWithFlavor(p2, theme_minimal(), "minimal + facet_grid")
themeWithFlavor(p, theme_classic(), "classic")
themeWithFlavor(p2, theme_classic(), "classic + facet_grid")
themeWithFlavor(p, theme_light(), "light")
themeWithFlavor(p2, theme_light(), "light + facet_grid")
themeWithFlavor(p, theme_grey(), "grey")