【发布时间】:2021-03-20 08:22:41
【问题描述】:
我正在尝试更改散点图中单个数据点(df 的第 101 个条目)的颜色。如何使用 matplotlib.animation 为更改设置动画?
首先,这是原始散点图:
import matplotlib.animation as animat
fig ,ax = plt.subplots()
fig.set_dpi(100)
fig.set_size_inches(15, 8)
groups = df.groupby('Name')
for name, group in groups:
ax.plot(group.SepalWidth,
group.SepalLength,
marker='o',
linestyle='',
label=name)
ax.legend(fontsize=10) # legend position
plt.title('Scatter Plot of Sabotaged Iris Data', fontsize=20)
plt.annotate('Sabotaged Data', xy=(3.31,6.305), xytext=(3.5,6.5), arrowprops = dict(facecolor ='black', shrink = 0.04))
plt.xlabel('Sepal Width', fontsize=14)
plt.ylabel('Sepal Length', fontsize=14)
现在我正在尝试随着帧的变化而改变颜色(可能是红色、橙色、黄色、粉红色、紫色),但我想不出如何填充更新功能:
def update(frame):
# ???
ani = animat.FuncAnimation(fig, update,
frames=360,
interval=0.01,
blit=True)
【问题讨论】:
标签: python matplotlib