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
In [1]:
In [2]:
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)
})
In [3]:
# Gallery, points
("x", "y"))
ggplot(df, aes(+ geom_point()
)
Coloured Point Bubbles
In [4]:
("x", "y", size="var1"))
ggplot(df, aes(+ geom_point(aes(color="var2"))
)
In [5]:
# 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")
)