[Python] How to align the facet size in plotnine?

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    When using the facet_grid function and setting angle=0, the rectangles are of different sizes depending on the length of the text. Is there a way to make them the same size?

    https://i.sstatic.net/XWkdFLTc.png

    import polars as pl
    from plotnine import *

    plot_base=pl.DataFrame(
    {
    "x":[1,1,1,1],
    "y":[1,1,1,1],
    "facet_x":["A","B","A","B"],
    "facet_y":["short","short","looooooong","looooooong"]
    }
    )

    (
    ggplot(
    data=plot_base,
    mapping=aes(x="x",
    y="y")
    )
    + geom_point()
    + facet_grid(rows="facet_y",
    cols="facet_x"
    )
    + theme(
    strip_text_y=element_text(angle=0)
    )
    )

    Continue reading...

Compartilhe esta Página