How to plot the number of times each element is in a list
matplotlib, python
Solution
This code gives you a histogram like the one you like:
import matplotlib.pyplot as plt
import numpy as np
y = np.array([0,1,2,3,4,5,6,7,8,9,1])
plt.hist(y);
plt.show()
Problem
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?