这是我要创建的图像,但是它应该有三个对应于条形的图例。
这是代码:
import numpy as np
import matplotlib.pyplot as plt
x=[1,2,3]
y=[399,499,100]
LABELS = ["node0", "node1", "failed"]
cr = ['g','r','b']
fig,ax = plt.subplots()
ax.bar(x,y,align='center',color=cr, Label='txed, rxed, failed')
plt.xticks(x, LABELS)
plt.legend()
plt.show()
答案 0 :(得分:0)
我认为你应该一次绘制每个条形图:
import numpy as np
import matplotlib.pyplot as plt
x=[1,2,3]
y=[399,499,100]
LABELS = ["node0", "node1", "failed"]
LEGENDS=['txed', 'rxed', 'failed']
cr = ['g','r','b']
fig,ax = plt.subplots()
for i in range(len(x)):
ax.bar(x[i],y[i],align='center',color=cr[i], label=LEGENDS[i])
plt.xticks(x, LABELS)
plt.legend()
plt.show()