我希望能在Python中制作一个饼图动画,它会根据数据不断变化(通过循环不断变化)。问题是它会逐个打印每个饼图,最终我会得到很多饼图。我希望一个饼图在原地改变,以便看起来像动画。有什么想法吗?
我正在使用以下代码:
我正在使用以下代码:
colors = ['gold', 'yellowgreen', 'lightcoral', 'lightskyblue', 'black', 'red', 'navy', 'blue', 'magenta', 'crimson']
explode = (0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, .01)
labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for num in range(1000):
str_num = str(num)
for x in range(10):
nums[x] += str_num.count(str(x))
plt.pie(nums, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=140)
plt.axis('equal')
plt.show()