File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed 
Python/Matplotlib/09-LiveData Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 11# Another way to do it without clearing the Axis
2+ from itertools import count
3+ import pandas as pd
4+ import matplotlib.pyplot as plt
5+ from matplotlib.animation import FuncAnimation
6+ 
7+ plt.style.use('fivethirtyeight')
8+ 
9+ x_vals = []
10+ y_vals = []
11+ 
12+ plt.plot([], [], label='Channel 1')
13+ plt.plot([], [], label='Channel 2')
14+ 
215
316def animate(i):
417    data = pd.read_csv('data.csv')
518    x = data['x_value']
619    y1 = data['total_1']
720    y2 = data['total_2']
821
22+     ax = plt.gca()
23+     line1, line2 = ax.lines
24+ 
925    line1.set_data(x, y1)
1026    line2.set_data(x, y2)
1127
12-     ax = plt.gca()
1328    xlim_low, xlim_high = ax.get_xlim()
1429    ylim_low, ylim_high = ax.get_ylim()
1530
@@ -24,3 +39,10 @@ def animate(i):
2439    current_ymin = y1min if (y1min < y2min) else y2min
2540
2641    ax.set_ylim((current_ymin - 5), (current_ymax + 5))
42+ 
43+ 
44+ ani = FuncAnimation(plt.gcf(), animate, interval=1000)
45+ 
46+ plt.legend()
47+ plt.tight_layout()
48+ plt.show()
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments