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] How do I make a matplotlib bar graph scale with the amount of items?

Discussão em 'Python' iniciado por Stack, Novembro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a small project and it is my first time using matplotlib, and I am struggling with how to make my bar graph look better with more inputs. The whole idea of the program is to read text documents and show the characters from most used to least used. It's a tool I decided to make for myself to help me with designing my split keyboard layout.

    The problem is the bigger the text document, the worse the bar graph looks. It always seems to be created at the exact same size so everything gets smushed. I have some screenshots of a few of my tests.

    best case scenario

    bad case

    worst case

    and this is the code that actually makes the graph

    names = list(sorted_count.keys())
    values = list(sorted_count.values())

    barplot = plt.bar(range(len(sorted_count)), values, tick_label=names, align="center")
    plt.bar_label(barplot, labels=values, label_type="edge" )
    plt.show()


    It just uses dictionaries of characters and their counts.

    Continue reading...

Compartilhe esta Página