has2k1 / plotnine

A Grammar of Graphics for Python

Home Page:https://plotnine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`geom_smooth` doesn't apply `alpha`

david-cortes opened this issue · comments

Passing argument alpha to geom_smooth doesn't end up applying transparency.

Example:

import numpy as np, pandas as pd, plotnine as p9
df = pd.DataFrame({
    "x": np.arange(100),
    "y" : np.arange(100) * np.random.random(size=100)
})
print(
    p9.ggplot(df, p9.aes(x="x", y="y"))
    + p9.geom_point(alpha=0.1)
    + p9.geom_smooth(alpha=0.1)
)

image

For geom_smooth the alpha aesthetic only applies to the confidence interval because commonly, you only want to see through that area and not the line.

You can set the colour of the line to rgba hex value e.g. color="#00000077" to get a transparent line.

Or, if you are mapping the color to a variable, you use staged evaluation to modify the color from rgb to rgba i.e.

aes(color=stage("col1", after_scale="make_transparent(color)"))

where

def make_transparent(rgb_seq):
    return [f"{c}77" for c in rgb_seq]