I've got a Python list representing a series of line segments that contains tuples of the form (x, y, z, color) where x, y, z are floats and color is a string describing what color the line should be in. I (or rather, the mecode library I'm using) is sticking the coordinates into numpy arrays X, Y, and Z.
When I render this list in matplotlib with:
from mpl_toolkits.mplot3d import Axes
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(X, Y, Z)
The 3D viewer performs rather well, but of course I don't get any colors.
But when I use the code suggested by Line colour of 3D parametric curve in python's matplotlib.pyplot:
for i in range(len(X)-1):
ax.plot(X[i:i+2], Y[i:i+2], Z[i:i+2],
color=self.position_history[i][3])
Things get much slower in the 3D render.
I am wondering what the nice Pythonic way is to iterate over the list elements that have the same color, so that I can reduce the number of calls to ax.plot. I'm making the assumption that this will make things faster.