fatesses 2019-07-18 15:02 采纳率: 50%
浏览 457
已采纳

关于python matplotlib的问题

import matplotlib.pyplot as plt
import numpy as np
bar_width = 0.4
plt.bar(left = np.arange(len(school)),height = group_ms,label = 'MS', color = 'steelblue',width = bar_width)
plt.bar(left = np.arange(len(school))+bar_width,height = group_gp,label = 'GP', color = 'indianred',width = bar_width)
plt.xticks(np.arange(3)+0.2,school)
plt.legend()
plt.show()

错误代码是:

TypeError                                 Traceback (most recent call last)
<ipython-input-80-f63fd0192e45> in <module>
      2 import numpy as np
      3 bar_width = 0.4
----> 4 plt.bar(left = np.arange(len(school)),height = group_ms,label = 'MS', color = 'steelblue',width = bar_width)
      5 plt.bar(left = np.arange(len(school))+bar_width,height = group_gp,label = 'GP', color = 'indianred',width = bar_width)
      6 plt.xticks(np.arange(3)+0.2,school)

TypeError: bar() missing 1 required positional argument: 'x'

数据是
图片说明

需要将两个学校的数据进行对比

  • 写回答

2条回答 默认 最新

  • 吃鸡王者 2019-07-18 16:25
    关注

    把plt.bar 中的left 换成x就可以了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?