Click here to Skip to main content
15,886,093 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to plot a continous flow of data coming from the serial. Data has 2 dimensions, let's say X and Y. I would like to plot these data against a third dimension, the time flowing. I wrote this code, but it doesn't do what i want.

Python
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.axes3d as p3
import numpy.random as rnd
import numpy as np

TILL = 200 # just to have an end in the for loop

def func(t):
	X = np.sin(t)
	Y = np.cos(t)
	T = t
	return X,Y,T

t = range(0,200)

plt.ion()
fig = plt.figure()
ax = fig.gca(projection='3d')
X,Y,T = func(t)
g, = ax.plot(X,Y,T)

plt.ylim([-1.5,1.5])
plt.xlim([-1.5,1.5])

for i in range(TILL):
	val = rnd.random(1)
	t.append(val)
	t.pop(0)
	X,Y,T = func(t)
	g.set_data(X,Y)
    ax.set_zlim(i,i+100)
    plt.draw()


It's as the problem of plotting a function from R to R square with sliding temporal axis.

Any help would be appreciate.
Thanks
Posted
Updated 27-Apr-15 12:17pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900