#๐Ÿ”’ matplotlib making bars with sorted names with counts

4 messages ยท Page 1 of 1 (latest)

sinful sequoia
#

hi hello
its my second time using matplotlib
this time trying to make bars plt.bar()
i found this tutorial
code:

def favorite_tanks():
    tanks = [
        i 
        for entry in contents 
        for i in entry.liketank
    ]
    sorted_tanks = sorted(tanks, key=lambda s: tanks.count(s))
    sorted_counts = sorted(list(collections.Counter(tanks).values()))
    counts_x = range(len(sorted_counts))

    plt.bar(counts_x, sorted_counts)
    plt.xticks(counts_x, sorted_tanks)
    plt.title("Favorite tanks")

full code: https://paste.pythondiscord.com/BHDQ
i am trying to create a bar, where each name has the height of the amount of times it was chosen in my google form
tanks is a flattened list, each containing a name, i want to count the occurence of each of the names, and then sort based off the results

In this matplotlib tutorial, I will walk you through how to plot a bar graph with matplotlib package in Python.

A bar graph is a visualization tool to present categorical data, and is also one of the most used chart types beside a line graph. This tutorial is catering toward beginners, so I will only cover just the basics in this lesson.

๐Ÿ“‘ Mat...

โ–ถ Play video
stark larkBOT
#

@sinful sequoia

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

stark larkBOT
#

@sinful sequoia

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.