python - “numpy.ndarray”对象没有属性“bar”
问题描述
我正在尝试为 uni 任务制作堆叠条形图。我不断收到错误消息('numpy.ndarray' 对象没有属性'bar')。有人可以帮我吗:D。找到下面的代码:
x = np.array(x)
data = x
attack, work, = data.shape
fig, ax = plt.subplots(nrows=1, ncols=2,figsize=(14, 5), dpi=100)
x_pos = np.arange(work)
width = 0.2
colours = ['red', 'yellow', 'blue', 'green']
labels = ['Cyber incident', 'Theft of paperwork or data storagedevice','Rogue employee', 'Social engineering and impersonation']
rotation = 90
for i in range(attack):
ax.bar(x_pos + i*width, data[:,], width=width, color=colours[i], label=labels[i], align='center')
i=i+1
ax.legend()
ax.set_xlabel("the top five industry sectors")
ax.set_ylabel("Number of attack")
ax.set_title("Type of attack by top five industry sectors")
ax.set_xticks(x_pos+width)
ax.set_xticklabels(labels, rotation)
解决方案
推荐阅读
- python - 如何在 H2OAutoML 中设置 weights_column?
- wso2esb - 向 mqtt 发送消息时如何启用 SSL
- c++ - 我如何在c中取数字的五次方
- python - 检查 tkinter 中的菜单项是启用还是禁用
- graphql-js - 我在 mergeschemas 上使用 graphql 时出现此错误:GraphQLError: Unknown type "Ability"
- sql - 不支持sql查询
- ios - Swift 5 - 无法解释的 DateFormatter 崩溃
- reactjs - 尝试导入错误:“createstore”未从“redux”导出
- python - 如何在使用 pandas 滚动相关性时解决不一致的结果?
- teensy - El Panel , Teensy LC 如何控制?