|
From: John H. <jd...@gm...> - 2008-03-25 14:49:54
|
On Sun, Mar 23, 2008 at 3:54 AM, Amit Finkler <ami...@gm...> wrote:
> I am using matplotlib to dynamically plot a graph with both my x and y
> points taken from a measurement device. That is to say, in each iteration of
> my while loop I'm reading two variables which I then want to plot with
> matplotlib.
You will want to do something like (this is just a sketch)
xdata = []
ydata = []
fig = figure()
ax = fig.add_subplot(111)
ax.set_xlabel('my xlabel')
ax.set_ylabel('my ylabel')
line, = ax.plot(xdata, ydata)
def add_point(x, y):
xdata.append(x)
ydata.append(y)
if len(xdata)>30: # optional, prune the early points
del xdata[0]
del ydata[0]
xmin = xdata[0]
xmax = xdata[-1]
line.set_data(xdata, ydata)
ax.set_xlim(xmin, xmax)
fig.canvas.draw()
while 1:
x,y = get_data_point()
add_point(x, y)
JDH
|