1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] plotnine: Hide or exclude labels for small values

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have

    [​IMG]

    and want the blue label to be hidden, since it's too small and gets overlapped by the purple one.

    test = (
    p9.ggplot(df, p9.aes('col1', fill='col2'))
    + p9.geom_bar()
    + p9.geom_label(
    p9.aes(
    label=p9.after_stat(
    'combine(count, count / sum(count) * 100)'
    ),
    color='col2'
    ),
    stat='count',
    position='stack',
    show_legend=False,
    boxstyle='square',
    boxcolor='black',
    size=7
    )


    I tried

    def combine(counts: pd.Series, percentages: pd.Series):
    fmt = "{} ({}%)".format
    cmax = max(counts)
    return [
    fmt(c, p) if c > (0.1 * cmax) else None
    for c, p
    in zip(counts, percentages, strict=True)
    ]


    to no avail.

    Continue reading...

Compartilhe esta Página