[Python] Matplotlib: unite entries in the legend with a bracket [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    So, I haven't found anything that could solve my problem.

    The issue is the following, I have a number of entries like: A, B, C, which belong to a group "Letters", I also have a symbol I, which is designated as I-Roman number and also there's a group of entries 1, 2, 3 which are "Arabic numbers". Several values belong to that group.

    import pandas as pd
    import matplotlib.pyplot as plt

    df = pd.read_csv('Test.csv', sep=';')
    df.head()
    print(df)

    #df.plot(x="nameEntry", y="valueEntry", kind="bar")
    #plt.show()

    fig, ax = plt.subplots()

    ax.bar(df["nameEntry"], df["valueEntry"])
    fig.subplots_adjust(bottom=0.28)
    plt.xticks(rotation=45)
    plt.show()


    Here's the code, which I use. And the output:

    [​IMG]

    What I want, however, is: [​IMG]

    What I want is to create a unifying bracket (I do not insist on curly brackets, or any brackets, any uniting sign/feature is acceptable) that describes the subentries of a group together. Is there any way to do this programmatically using matplotlib?

    The data:

    nameEntry;valueEntry
    A;45216
    B;21739
    C;32179
    I - Roman number;73218
    1;819023
    2;291
    3;38910

    Continue reading...

Compartilhe esta Página