Back to Article
aes
Download Notebook

aes

In [1]:
import pandas as pd
import numpy as np

from plotnine import ggplot, aes, geom_point

Mapping variables to the visual properties of a plot.

In [2]:
df = pd.DataFrame({
    "col1": np.arange(11),
    "col2": np.arange(11)
})

(
    ggplot(df, aes(x="col1", y="col2"))
    + geom_point()
)

In [3]:
(
    ggplot(df, aes(x="col1", y="col2 ** 2"))
    + geom_point()
)

In [4]:
(
    ggplot(df, aes(x="col1", y="np.square(col2)"))
    + geom_point()
)

The first two positional arguments are x and y aesthetics. Any other aesthetic must be mapped with a keyword argument.

In [5]:
(
    ggplot(df, aes("col1", "np.square(col2)", color="col2"))
    + geom_point(size=3)
)