我有一个使用matplotlib绘制的饼图。除了这个饼图我有一个滑块,当按下时会调用一个处理程序。我希望这个处理程序改变饼图的值。例如,如果饼图分别具有60%和40%的标签,我希望在按下滑块时将标签修改为90%和10%。下面是代码:使用matplotlib刷新我的饼图?
此提请饼图和滑块:
plt.axis('equal');
explode = (0, 0, 0.1);
plt.pie(sizes, explode=explode, labels=underlyingPie, colors=colorOption,
autopct='%1.1f%%', shadow=True, startangle=90)
plt.axis('equal')
a0 = 5;
axcolor = 'lightgoldenrodyellow'
aRisk = axes([0.15, 0, 0.65, 0.03], axisbg=axcolor)
risk = Slider(aRisk, 'Risk', 0.1, 100.0, valinit=a0)
risk.on_changed(update);
和以下是事件处理程序中,所希望的功能是修改标签和重绘饼图
def update(val):
riskPercent = risk.val;
underlyingPie[0] = 10;
underlyingPie[1] = 90;
plt.pie(sizes, explode=explode, labels=lab, colors=colorOption,
autopct='%1.1f%%', shadow=True, startangle=90)
我也在画下面,我可以在同一个画布上同时获取饼图和下面的图吗?
fig = plt.figure();
ax1 = fig.add_subplot(211);
for x,y in zip(theListDates,theListReturns):
ax1.plot(x,y);
plt.legend("title");
plt.ylabel("Y axis");
plt.xlabel("X axis");
plt.title("my graph");
在此先感谢
那么问题是什么? – tacaswell
当滑块被调用时用新值重绘饼图 – godzilla
我收集了这个,但你的代码看起来或多或少正确,什么是不工作? – tacaswell