import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
def gggrid(plots=[], width=400, height=300, columns=2):
bunch = GGBunch()
for i in range(len(plots)):
row = int(i / columns)
column = i % columns
bunch.add_plot(plots[i], column * width, row * height, width, height)
return bunch.show()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-kotlin/master/docs/examples/data/mpg.csv")
print(df.shape)
df.head()
(234, 12)
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 |
p = ggplot(df, aes("cty", "hwy", color="drv")) + geom_point()
gggrid([
p + ggtitle("theme_minimal2() - the default"),
p + theme_grey() + ggtitle("theme_grey()"),
p + theme_bw() + ggtitle("theme_bw()"),
p + theme_light() + ggtitle("theme_light()"),
p + theme_classic() + ggtitle("theme_classic()"),
p + theme_minimal() + ggtitle("theme_minimal()"),
])
pf = p + facet_grid(x="drv")
gggrid([
pf + ggtitle("theme_minimal2() - the default"),
pf + theme_grey() + ggtitle("theme_grey()"),
pf + theme_bw() + ggtitle("theme_bw()"),
pf + theme_light() + ggtitle("theme_light()"),
pf + theme_classic() + ggtitle("theme_classic()"),
pf + theme_minimal() + ggtitle("theme_minimal()"),
], width=700, height=200, columns=1)