Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Bar Chart
- import matplotlib.pyplot as plot
- import random #just to generate data for testing
- # Add your count function here
- def count(target_grade,scores_list):
- target_hits = 0
- for score in scores_list:
- if score == target_grade:
- target_hits += 1
- return target_hits
- # Preparing raw data for bar chart: occurrence counts
- def bar_chart_counts(scores):
- scores_bar = []
- for x in range(11):
- scores_bar.append(count(x, scores))
- print("Bar chart data: ", scores_bar)
- sum = 0
- for index in range(len(scores_bar)):
- sum += scores_bar[index]
- if sum == len(scores):
- print("total number of data points in bar chart is: ", sum)
- return scores_bar
- else:
- print("Warning: there is something wrong here.")
- # Produce a bar chart from raw data, original scores
- def construct_bar_chart(scores):
- scores_bar = bar_chart_counts(scores) #generate occurrence count
- plot.bar(range(11), scores_bar, align='center', alpha=0.5)
- plot.xticks(range(11))
- plot.ylabel('Score frequency')
- plot.title('Scores on a quiz')
- plot.show()
- plot.savefig(fname="Quiz Chart.png")
- # "Create" a list of scores, randomly
- scores = []
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- print("list of scores ", scores)
- #####################################
- construct_bar_chart(scores)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement