首页 > 解决方案 > “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)

标签: pythonpython-3.xnumpymatplotlib

解决方案


推荐阅读