I am using matlibplot to plot a 3d graph of scatter points as shown in below code.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.ion()
plt.show()
ax.set_xlim([0.,13.])
ax.set_ylim([-1.5,1.5])
ax.set_zlim([-1.5,1.5])
def plotPoint(x,y,z):
ax.scatter(x, y, z)
In above code plotPoint(x,y,z)
is called in while True
loop after very Serial.readLine()
With out this plot I was able to log data in console for every 20 mill seconds.But after started plotting those in graph it become very slow.
How to make this fast? Are there any other python libraries that can help me to visualize 3d points in plots.I am using OpenCV also in my project.I case if there are any solution for my problem with opencv.
Edited code as suggested by unutbu:
list_data = []
xdata = []
ydata = []
zdata = []
def update_graph(i):
global xdata
global ydata
global zdata
global list_data
print i, list_data
for x in list_data:
xdata.append(x[0][0])
ydata.append(x[1][0])
zdata.append(x[2][0])
graph.set_data (xdata, ydata)
graph.set_3d_properties(zdata)
title.set_text('3D Test')
return title, graph,
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
title = ax.set_title('3D Test')
graph, = ax.plot(xdata, ydata, zdata, linestyle="", marker="o")
ani = matplotlib.animation.FuncAnimation(fig, update_graph,
interval=100, blit=True)
plt.show()