import pandas as pd
from lets_plot.bistro import *
from lets_plot import *
LetsPlot.setup_html()
df = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/iris.csv")
print(df.shape)
df.head()
In the simplest case, assign x and y to create a scatterplot (using geom_point()) with marginal histograms (using geom_histogram()).
joint_plot(df, "petal_length", "petal_width")
Besides the points there are another two types of geoms: tile and density2d(f).
joint_plot(df, "petal_length", "petal_width", geom='tile')
joint_plot(df.dropna(), "petal_length", "petal_width", color_by="species", geom='density2d')
Use additional parameters for better customization: color, size, alpha, etc.
joint_plot(df, "petal_length", "petal_width", color="#756bb1", size=8, alpha=.5, se=False)
joint_plot(df, "petal_length", "petal_width", color="black", marginal="box:lb:.03,hist:t:.4,hist:r") + \
ggmarginal("tr", layer=geom_area(stat='density', color="magenta", fill="magenta", alpha=.1)) + \
theme(axis_line_x='blank', axis_line_y='blank')
joint_plot(df, "petal_length", "petal_width", color_by="species", marginal="hist:tr")
Add any other layer that supports x and y aesthetics (e.g. points layer with the geom_point() function).
joint_plot(df, "petal_length", "petal_width", geom='density2df', \
color="#993404", alpha=1/3, reg_line=False) + \
geom_point(size=5, shape=21, color="#993404", fill="#ffffd4") + \
scale_fill_gradient(low="#d95f0e", high="#fff7bc")