我需要使用matplotlib创建一个堆积条形图。每个条形应该是我正在测量的参数的堆栈。但是,我希望它是交互式或动态的,因此当我在图例中点击其中一个参数(例如A、B、C)时,它应该将该参数放在堆栈底部,以便我们可以根据我们选择的参数更好地比较不同的候选者。
我受到matplotlib示例的启发...这是我的代码:
我受到matplotlib示例的启发...这是我的代码:
import numpy as np
import matplotlib.pyplot as plt
N = 10 #could change
plt.figure()
A = np.array([70, 88, 78, 93, 99, 58, 89, 66, 77, 78])
B = np.array([73, 65, 78, 87, 97, 57, 77, 88, 69, 78])
C = np.array([66, 98, 88, 67, 99, 88, 62, 70, 90, 73])
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
p1 = plt.bar(ind, A,width, color='r')
p2 = plt.bar(ind, B, width, color='y', bottom=A)
p3 = plt.bar(ind, C, width, color='b', bottom=A+B)
plt.ylabel('Scores')
plt.title('Index')
plt.xticks(ind+width/2., ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10'))#dynamic - fed
plt.yticks(np.arange(0,300,10))
plt.legend( (p1[0], p2[0], p3[0]), ('A','B','C') )
plt.grid(True)
plt.show()
谢谢...我希望我的表述足够清晰