Here is my example:
import matplotlib.pyplot as plt
test_list = ['a', 'b', 'b', 'c']
plt.hist(test_list)
plt.show()
It generates the following error message:
TypeError Traceback (most recent call last)
<ipython-input-48-228f7f5e9d1e> in <module>()
1 test_list = ['a', 'b', 'b', 'c']
----> 2 plt.hist(test_list)
3 plt.show()
C:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in hist(x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, hold, data, **kwargs)
2956 histtype=histtype, align=align, orientation=orientation,
2957 rwidth=rwidth, log=log, color=color, label=label,
-> 2958 stacked=stacked, data=data, **kwargs)
2959 finally:
2960 ax.hold(washold)
C:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, *args, **kwargs)
1809 warnings.warn(msg % (label_namer, func.__name__),
1810 RuntimeWarning, stacklevel=2)
-> 1811 return func(ax, *args, **kwargs)
1812 pre_doc = inner.__doc__
1813 if pre_doc is None:
C:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in hist(self, x, bins, range, normed, weights, cumulative, bottom, histtype, align, orientation, rwidth, log, color, label, stacked, **kwargs)
5993 xmax = -np.inf
5994 for xi in x:
-> 5995 if len(xi) > 0:
5996 xmin = min(xmin, xi.min())
5997 xmax = max(xmax, xi.max())
TypeError: len() of unsized object
I only briefly search on google, but it looks like I cannot plot histogram for categorical variables in matplotlib.
Can anybody confirm?