has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.89k stars 209 forks source link

geom_text: family aesthetic does not seem to use mappings #790

Closed machow closed 1 month ago

machow commented 1 month ago

Manually specifying sans-serif or serif seems to work. But using those in a mapping to family doesn't seem to work (at least on my Mac). (I also noticed that there doesn't seem to be support for "mono", but that might be worth a separate issue?)

from plotnine import *
import pandas as pd

df = pd.DataFrame({"x": 1, "y": [2, 1], "family": ["sans-serif", "serif"]})

# doesn't seem to be used, everything is sans-serif
(
  ggplot(df, aes("x", "y")) + 
  geom_text(aes(label = "family", family="family"), size=20)
)
image
# works (all sans-serif)
(
  ggplot(df, aes("x", "y")) + 
  geom_text(aes(label = "family"), family = "sans-serif", size=20)
)
image
# also works (all serif)
(
  ggplot(df, aes("x", "y")) + 
  geom_text(aes(label = "family"), family = "serif", size=20)
)
image
has2k1 commented 1 month ago

Currently font family is a parameter and not an aesthetic but we can make it an aesthetic.