python - 如何在 matplotlib 中获得动画效果?
问题描述
嘿,每次运行 animattion_frame 函数时,我一直试图将条形图上的第四条增加三,但无论我做什么,它都不想工作。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
N = 5
menMeans = [20, 35, 30, 35, 27]
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax1 = plt.subplots()
#plt.bar(ind, menMeans, width)
ax=plt.yticks(np.arange(0, 81, 10))
def animation_frame(ind,i,menMeans):
#x_data.append(i * 10)
menMeans[3]=menMeans[3]+3
ax=plt.clear()
ax=plt.bar(ind,menMeans,width)
return ax
animation = FuncAnimation(fig,fargs=(menMeans,ind), func=animation_frame, interval=100)
plt.show()
解决方案
您的代码发生了很多奇怪的事情,但我试图挽救其中的大部分。这是你想要达到的目标吗?
N = 5
menMeans = [20, 35, 30, 35, 27]
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
fig, ax1 = plt.subplots()
ax1.set_yticks(np.arange(0, 81, 10))
def animation_frame(i, menMeans, ind):
menMeans[3] += 3
ax1.cla()
ret = ax1.bar(ind,menMeans,width)
return ret,
animation = FuncAnimation(fig,fargs=(menMeans, ind), func=animation_frame, interval=100)
plt.show()
推荐阅读
- javascript - 我是否需要创建一个图像文件夹才能使 javascript 照片库正常工作?
- one-hot-encoding - 数据销毁模型的 One-Hot 编码?
- javascript - 如何连接 document.location.href 路径中的变量?
- python - 如何在 Windows 上获取有关硬盘的详细信息
- vuejs2 - 如何在 VueJs v-for 中显示图像
- ios - 导航控制器的最佳实践
- python - pygame中的面具之间的碰撞
- sql - SQL查询到节点红色折线图
- c - 统一测试时忽略用户输入
- python - 如何退出在多处理池中运行的 starmap_async 进程?