Django问题:TypeError: unsupported operand type(s) for -: ‘str‘ and ‘float‘

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

参考链接

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值