无法显示在Matplotlib条形图动画 [英] Can't show animation for bar graph in Matplotlib

查看:370
本文介绍了无法显示在Matplotlib条形图动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不断更新单个值的文本文件。我试图使用matplotlib的动画来显示该值,但我有很多的问题。例如,我想证明的(取值范围为0〜150)改变每一秒在文本文件中的值,我想柱状图的高度增加,这个值减少。

我想要做同样的水平图。我也想展示一个点周围一圈为不同的移动值(0〜360)。

我试过很多东西,但它不断地突破了code或matplotlib僵住了。我一直在尝试使用matplotlib的动画。

任何帮助将是AP preciated。
当我运行code我看不到条形图

 进口matplotlib.pyplot如PLT
进口mpl_toolkits.mplot3d.axes3d为P3
进口matplotlib.animation动画
进口随机MF = R的data.txt图= plt.figure()
AX = p3.Axes3D(图)
XPOS = 0
ypos = 0
zpos = 0
DX = 1
DY = 1高清update_bars():
    MMF =开(MF)
    线= mmf.readlines()
    depth_1 =行[3]
    DZ = depth_1
    酒吧= ax.bar3d(XPOS,ypos,zpos,DX,DY,DZ,颜色='B')
    返回杆##条增加
ax.set_title(深度)line_ani = animation.FuncAnimation(图,update_bars,500,时间间隔= 100)
plt.show()


解决方案

只是不得不改变depth_1 =行[3]这depth_1 = INT(行[3])

I have a text file that is constantly updating a single value. I'm trying to display this value using matplotlib's animation but I'm having lots of issues. For example I want to show a value that's changing every second on the text file (value ranges from 0 to 150) and I want the height of bar graph to increase and decrease with this value.

I want to do the same with horizontal graph. I also want to show a dot moving around the circle for different values (between 0 and 360).

I've tried to many things but it constantly broke the code or matplotlib froze. I've been trying to use matplotlib's animation.

Any help would be appreciated. When I run the code I don't see the bar graph

import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
import random

mf = r"data.txt"

fig = plt.figure()
ax = p3.Axes3D(fig)
xpos = 0
ypos = 0
zpos = 0
dx = 1
dy = 1





def update_bars():
    mmf = open(mf) 
    lines = mmf.readlines()
    depth_1 = lines[3]
    dz = depth_1


    bars = ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color= 'b')
    return bars

## add bars


ax.set_title('Depth')

line_ani = animation.FuncAnimation(fig, update_bars, 500, interval=100)
plt.show()

解决方案

Just had to change depth_1 = lines[3] to this depth_1 = int(lines[3])

这篇关于无法显示在Matplotlib条形图动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆