import pandas as pd
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/refs/heads/master/data/diamonds.csv")
print(df.shape)
df.head()
p = ggplot(df, aes("carat", "price")) + scale_fill_viridis(trans='symlog')
p + geom_hex()
p + geom_hex(bins=[5, 10]) + ggtitle("bins=[5, 10]")
p + geom_hex(binwidth=[1, 5000]) + ggtitle("binwidth=[1, 5000]")
p + geom_hex(binwidth=[1, 5000], drop=False) + ggtitle("drop=False")
'binhex' Stat¶ggplot(df, aes("carat", "price")) + \
geom_point(aes(color='..count..'), stat='binhex',
binwidth=[1, 5000], drop=False,
size=.75, size_unit='x') + \
coord_cartesian(xlim=[-1, 7], ylim=[-2_500, 25_000])
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/italy_cdi.csv")\
[["CDI", "No. of responses", "Latitude", "Longitude"]]
df.columns = ["CDI", "number_of_responses", "lat", "lon"]
print(df.shape)
df.head()
ggplot(df) + \
geom_livemap(location=[15, 41], zoom=7) + \
geom_hex(aes(x="lon", y="lat", weight="number_of_responses", fill="..count.."),
binwidth=[.5, .5], size=.5, color="#081d58", alpha=.5) + \
scale_fill_brewer(name="Number of responses", type='seq', palette="YlGnBu") + \
ggtitle("Community Internet Intensity Map",
"M 4.7 - 1 km NW of Montagano, Italy") + \
theme(plot_title=element_text(face='bold'))