0

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()
222
  • 95
  • 1
  • 8
  • 1
    You have listed too many problems for that one question. If you don't see the bar graph, it is going to be difficult to animate it! Please, (1) provide a minimal example that includes data, and (2) ask a single focused question at a time. – Reblochon Masque Apr 25 '16 at 05:16
  • Good point by Reblochon. Complexity often kills you, better to separate issues. Why not leave the file reading out and just have the `update` function generate a random value. – roadrunner66 Apr 25 '16 at 06:17
  • @ReblochonMasque I cut out the code a lot to simply the problem. this is supposed to update a bar chart every second. the depth is an integer between 0 and 50. the data is 5 lines (each line holding an integer) that updates every second. line 3 is depth which is shown as depth_1. all i need is the graph updating every second. – 222 Apr 25 '16 at 07:51
  • Do you have a graph that you can see? Provide mock data so it can be reproduced... It is very difficult to animate a graph that doesn't exist. – Reblochon Masque Apr 25 '16 at 07:54
  • @ReblochonMasque this is the example I'm going off of: http://stackoverflow.com/questions/35455041/example-of-animated-3d-bar-chart-using-matplotlib-animation-in-python This is what I see when I run the code without opening a text file everytime: http://prntscr.com/awj2bu The code is next to it as well – 222 Apr 25 '16 at 08:14
  • I still don't have data to reproduce where you are at. – Reblochon Masque Apr 25 '16 at 08:26
  • @ReblochonMasque here's sample data: http://textuploader.com/5y7gk – 222 Apr 25 '16 at 08:30
  • @ReblochonMasque nevermind. I fixed it. changed this: depth_1 = lines[3] to this depth_1 = int(lines[3]) – 222 Apr 25 '16 at 08:38

1 Answers1

0

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

222
  • 95
  • 1
  • 8