Django问题:TypeError: unsupported operand type(s) for -: ‘str’ and 'float
Traceback (most recent call last):
File "C:\Users\ASUS\Anaconda3\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\ASUS\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\ASUS\Anaconda3\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\ASUS\Desktop\wstest\app\views.py", line 333, in msg_send
chartpath = getChart(str(summarize))
File "C:\Users\ASUS\Desktop\wstest\app\views.py", line 258, in getChart
plt.barh(keys, values, color='steelblue')
File "C:\Users\ASUS\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 2725, in barh
ret = ax.barh(bottom, width, height=height, left=left, **kwargs)
File "C:\Users\ASUS\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 2285, in barh
bottom=bottom, orientation='horizontal', **kwargs)
File "C:\Users\ASUS\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1897, in inner
return func(ax, *args, **kwargs)
File "C:\Users\ASUS\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 2108, in bar
for i in xrange(len(bottom))]
File "C:\Users\ASUS\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 2108, in <listcomp>
for i in xrange(len(bottom))]
TypeError: unsupported operand type(s) for -: 'str' and 'float'
解决方法:
错误的原因是第一个参数(x)必需是数字,所以如下修改
x = range(len(keys))
plt.bar(x, values)
plt.xticks(x, keys)#如果改变y轴 则yticks