【发布时间】:2020-11-08 01:28:38
【问题描述】:
我正在尝试使用 Matplotlib 的 FuncAnimation 函数来更新饼图并制作 gif。我已经问过this question,但并没有太大的吸引力。所以这是我的数据集,一个熊猫系列的列表,我将其称为numbers,如下所示:
[[6.166, 5.976, 3.504, 7.104, 5.14],
[7.472, 5.888, 3.264, 6.4825, 7.168],
[7.5716, 9.936, 3.6, 8.536, 2.808],
[2.604, 2.296, 0.0, 6.144, 4.836],
[7.192, 4.932, 0.0, 6.016, 8.808],
[7.192, 5.5755, 3.694, 9.376, 9.108],
[7.63616, 5.912, 3.968, 6.672, 3.192],
[3.41049, 5.44, 4.004, 7.212, 3.6954],
[4.3143, 6.364, 3.584, 7.44, 5.78],
[4.992, 3.9692, 4.272, 0.0, 2.528]]
这是我正在使用的代码:
colors = ["yellow", "red", "purple", "blue", "green"]
explode = [0.01, 0.01, 0.01, 0.01, 0.01]
labels = ["DM", "Bard", "Warlock", "Paladin", "Ranger"]
z = [0,0,0,0,0]
fig,ax = plt.subplots()
def update(num):
ax.axis('equal')
global z
for x in range(0,10):
z += numbers[x]
z = z.tolist()
ax.pie(z, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=140)
ax.set_title(sum(z))
ani = FuncAnimation(fig, update, frames=range(10), repeat=False)
plt.show()
输出:
根据此输出,只有总数会显示在最后一帧中。没有中间动画正在进行。我已阅读 this question 并回答,但我无法弄清楚为什么这不起作用。
【问题讨论】:
标签: python pandas matplotlib