Demo entry 6756206



Submitted by anonymous on Aug 02, 2018 at 22:09
Language: Python 3. Code size: 1.2 kB.

import matplotlib.pyplot as plt
import numpy as np

# use ggplot style for more sophisticated visuals'ggplot')

def live_plotter(x_vec,y1_data,line1,identifier='',pause_time=0.1):
    if line1==[]:
        # this is the call to matplotlib that allows dynamic plotting
        fig = plt.figure(figsize=(13,6))
        ax = fig.add_subplot(111)
        # create a variable for the line so we can later update it
        line1, = ax.plot(x_vec,y1_data,'-o',alpha=0.8)        
        #update plot label/title
        plt.ylabel('Y Label')
        plt.title('Title: {}'.format(identifier))
    # after the figure, axis, and line are created, we only need to update the y-data
    # adjust limits if new data goes beyond bounds
    if np.min(y1_data)<=line1.axes.get_ylim()[0] or np.max(y1_data)>=line1.axes.get_ylim()[1]:
    # this pauses the data so the figure/axis can catch up - the amount of pause can be altered above
    # return line so we can update it again in the next iteration
    return line1

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).