【发布时间】:2017-07-06 01:03:57
【问题描述】:
我正在尝试在 matplotlib 中为茎图制作动画,但找不到必要的文档来帮助我。我有一系列数据文件,每个文件看起来像这样:
1 0.345346
2 0.124325
3 0.534585
我想将每个文件绘制为一个单独的框架。
根据this 和this other 教程,我应该创建一个函数来更新每个绘图对象中包含的数据(艺术家?我不确定术语)
从第二个链接来看,这是更新函数
def update(frame):
global P, C, S
# Every ring is made more transparent
C[:,3] = np.maximum(0, C[:,3] - 1.0/n)
# Each ring is made larger
S += (size_max - size_min) / n
# Reset ring specific ring (relative to frame number)
i = frame % 50
P[i] = np.random.uniform(0,1,2)
S[i] = size_min
C[i,3] = 1
# Update scatter object
scat.set_edgecolors(C)
scat.set_sizes(S)
scat.set_offsets(P)
# Return the modified object
return scat,
我怎样才能使这种更新功能适用于茎图? stem 的 documentation 非常简短(实际上这是我正在学习 matplotlib 时反复出现的问题),但 example code 表明 stem 的输出是元组 markerline, stemlines, baseline 而不是艺术家对象,例如 plt.plot 或 plt.imshow。
那么,当我为动画编写 update 函数时,如何更新主干图中的数据?
【问题讨论】:
标签: python animation matplotlib plot