3

I am trying to make a 3D plot from x, y, z points list, and I want to plot color depending on the values of a fourth variable rho.

Currently I have ;

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot3D(cell_x, cell_y, cell_z, linestyle='None', marker='o', markersize = 5, antialiased=True)
ax.set_xlim3d(0.45, 0.55)
ax.set_ylim3d(0.45, 0.55)
ax.set_zlim3d(0.45, 0.55)

How to add cell_rho (my fourth array) as the color of my x, y, z points ? (for example for a jet colormap).

Thank you very much.

EDIT : I can't use scatter plots because for my 18000 points scatter plots are very slow compared to plot3d with markers only.

Vincent
  • 57,703
  • 61
  • 205
  • 388
  • Something along these lines: http://stackoverflow.com/questions/9134879/how-to-plot-a-multicolored-curve-using-a-single-plot-command-in-matplotlib ? – ev-br Feb 06 '12 at 18:22
  • Even with that, I don't understand how to convert rho to values that can be passed to the "color" option of my plot 3D... – Vincent Feb 06 '12 at 18:33
  • Are you trying to mashup a multicolored line (http://www.scipy.org/Cookbook/Matplotlib/MulticoloredLine) and 3d line (http://matplotlib.sourceforge.net/mpl_toolkits/mplot3d/tutorial.html#line-plots)? – matt Feb 06 '12 at 20:24

1 Answers1

7

If you want to display a simple 3D scatterplot, can't you just use scatter?
E.g.,

x, y, z = randn(100), randn(100), randn(100)
fig = plt.figure()
from mpl_toolkits.mplot3d import Axes3D
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c=randn(100))
plt.show()

(I'm running the above code under python -pylab.)

enter image description here

It seems, on the contrary, that with plot3D you must convert your fourth dimension to RGB tuples.

chl
  • 27,771
  • 5
  • 51
  • 71
  • My problem is that for my 18000 points scatter plots are way slower than plot3D with markers only... – Vincent Feb 07 '12 at 09:03