import numpy as np
import pandas as pd
from plotnine import (
ggplot,
aes,
geom_point,
theme_matplotlib,
theme_set,
)
# Set default theme for all the plots
theme_set(theme_matplotlib())
Basic Scatter Plot
123)
np.random.seed(= 150
n
= pd.DataFrame({
df "x": np.random.randint(0, 101, n),
"y": np.random.randint(0, 101, n),
"var1": np.random.randint(1, 6, n),
"var2": np.random.randint(0, 11, n)
})
# Gallery, points
("x", "y"))
ggplot(df, aes(+ geom_point()
)
Coloured Point Bubbles
("x", "y", size="var1"))
ggplot(df, aes(+ geom_point(aes(color="var2"))
)
# Gallery, points
("x", "y", size="var1"))
ggplot(df, aes(+ geom_point(aes(fill="var2"), stroke=0, alpha=0.5)
+ geom_point(aes(color="var2"), fill="none")
)