我要绘制的柱状图中,这里是数据:matplotlib.pyplot.plot,ValueError异常:无法将字符串转换为float:一个
large_letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
large_num = [52909, 52911, 52912, 52911, 52912, 52912, 52912, 52912, 52912, 52911]
small_letter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
small_num = [1872, 1873, 1873, 1873, 1873, 1872, 1872, 1872, 1872, 1872]
我想绘制2个次要情节,以显示每个字母“在每个表号,所以这里是我的代码
import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.bar(large_letter, large_num)
ax2.bar(small_letter, small_num)
但它返回以下错误:
ValueErrorTraceback (most recent call last)
<ipython-input-90-e23f798dd50c> in <module>()
20 fig, (ax1, ax2) = plt.subplots(1, 2)
---> 21 ax1.bar(large_letter, large_num)
22 ax2.bar(small_letter, small_num)
/usr/lib64/python2.7/site-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1817 warnings.warn(msg % (label_namer, func.__name__),
1818 RuntimeWarning, stacklevel=2)
-> 1819 return func(ax, *args, **kwargs)
1820 pre_doc = inner.__doc__
1821 if pre_doc is None:
/usr/lib64/python2.7/site-packages/matplotlib/axes/_axes.pyc in bar(self, left, height, width, bottom, **kwargs)
2085 edgecolor=e,
2086 linewidth=lw,
-> 2087 label='_nolegend_'
2088 )
2089 r.update(kwargs)
/usr/lib64/python2.7/site-packages/matplotlib/patches.pyc in __init__(self, xy, width, height, angle, **kwargs)
638 Patch.__init__(self, **kwargs)
639
--> 640 self._x = float(xy[0])
641 self._y = float(xy[1])
642 self._width = float(width)
ValueError: could not convert string to float: A
我怎样才能解决这个问题?谢谢!