How to plot the number of times each element is in a list

Viewed 17214

I'm trying to do something slightly that I wouldn't think would be hard, but I can't figure out how to get python/matplotlib/pylab to do.

Given an input, I want a histogram that shows me the number of times each element appears.

Given a list

x=range(10)

I'd like output that has a single bar, y value of 10, equal to x=1, no other graphs.

given a list

x=range(10)
x.append(1)

I'd like the output to have two bars, a y value of 9 for x=1, a y value of 1 for x=2. How can I do this?

4 Answers
Related