0

I want to try to graph a histogram for an array of "Team" objects based on a random score attribute that I give them, like so:

class Team(object):
    def __init__(self):
        self.score = random.randint(1,1000)

#What goes after this?

1 Answer 1

1
import matplotlib.pyplot as plt
import random

class Team(object):
    def __init__(self):
        self.score = random.randint(1,1000)

def plot_hist(teams, bins=40):
    scores = [team.score for team in teams]
    plt.hist(scores, bins)
    plt.show()

teams = [Team() for _ in range(1000)]

plot_hist(teams)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.