I am having a major setback on this question on a while now…
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
fig = plt.figure(1)
ax = fig.add_subplot(111)
ax.set_title("linear realtime")
line, = ax.plot([],[])
i = 0
while ( i < 1000 ):
#EDIT:
# this is just sample data, but I would eventually like to set data
# where it can be floating numbers...
line.set_data(i,i)
fig.canvas.draw()
i += 1
I am trying to draw a linear line in real time but I am unable to come up with the result. Thanks in advance. So far, I have a figure coming up but nothing is being drawn on the canvas.
EDIT:
Interesting…. I am now able to plot the dots on the line but now, I am unable to show their connectivity between each point… I also noticed that if you removed ko- when it is being plotted… nothing appears, does anybody know why?
import numpy as n
import pylab as p
import time
x=0
y=0
p.ion()
fig=p.figure(1)
ax=fig.add_subplot(111)
ax.set_xlim(0,10)
ax.set_ylim(0,10)
line,=ax.plot(x,y,'ko-')
for i in range(10):
x = i
y = i
line.set_data(x,y)
p.draw()
add a
p.pause(.001)in your loop. You need to allow time for the gui event loops to trigger and update the display.This is related to issue #1646.
The other issue you have is that when you do
set_datait replaces the data that is plotted with thexandypassed in, not append to the data that is already there. (To see this clearly usep.pause(1)) When you remove'ko-', which defaults to no marker with a line connecting points you are plotting a single point, hence nothing shows up.I think you intended to write this: