Skip to content

Instantly share code, notes, and snippets.

@fbkarsdorp
Last active August 29, 2015 14:07
Show Gist options
  • Save fbkarsdorp/7856ca59b4a4a98eb9e6 to your computer and use it in GitHub Desktop.
Save fbkarsdorp/7856ca59b4a4a98eb9e6 to your computer and use it in GitHub Desktop.
Class for interactive plots
import matplotlib.pyplot as plt
class InteractivePlot(object):
def __init__(self, id, xlabel, ylabel):
self.id = id
plt.figure(id)
plt.ion()
self.xlabel = xlabel
self.ylabel = ylabel
self.x = []
self.y = []
def update(self, xval, yval):
x = self.x
y = self.y
x.append(xval)
y.append(yval)
plt.figure(self.id)
plt.clf()
plt.plot(x, y, 'k')
plt.xlabel(self.xlabel)
plt.ylabel(self.ylabel)
plt.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment