Skip to content

fontstyle does not work with geom_text #941

Open

Description

@machow

possibly related to #940

Using plotnine version '0.15.0a2.post3+g2cdc487f'

import pandas as pd
from plotnine import *

df = pd.DataFrame({"x": [1, 2, 3], "fontstyle": ["normal", "italic", "oblique"]})

(ggplot(df, aes(1, "x")) + geom_text(aes(label="fontstyle", fontstyle="fontstyle")))
Image

Activity

  1. has2k1 commented on May 26, 2025

    @has2k1
    Owner

    This is a matplotlib issue. It cannot handle fontstyle for fonts that pack all they styles in a single file i.e. .ttc The default font is Helvetica, if you have it installed and it is probably a single Helvetica.ttc!

    You can check with:

    import matplotlib.font_manager as fm
    for font in fm.findSystemFonts():
        if "helvetica" in font.lower():
            print(font)

    If you try DejuVu Sans or Arial the fontstyle should work.

    import pandas as pd
    from plotnine import *
    
    df = pd.DataFrame({"x": [1, 2, 3], "fontstyle": ["normal", "italic", "oblique"]})
    
    (
        ggplot(df, aes(1, "x"))
        + geom_text(aes(label="fontstyle", fontstyle="fontstyle"), family="Arial")
    )
  2. machow commented on Jun 3, 2025

    @machow
    ContributorAuthor

    Ah, thanks for clarifying! This is super helpful! Feel free to close if useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions