python - pylab 3d scatter plots with 2d projections of plotted data -
i trying create simple 3d scatter plot want show 2d projection of data on same figure. allow show correlation between 2 of 3 variables might hard see in 3d plot.
i remember seeing somewhere before not able find again.
here toy example:
x= np.random.random(100) y= np.random.random(100) z= sin(x**2+y**2) fig= figure() ax= fig.add_subplot(111, projection= '3d') ax.scatter(x,y,z)
you can add 2d projections of 3d scatter data using plot
method , specifying zdir
:
import numpy np import matplotlib.pyplot plt x= np.random.random(100) y= np.random.random(100) z= np.sin(3*x**2+y**2) fig= plt.figure() ax= fig.add_subplot(111, projection= '3d') ax.scatter(x,y,z) ax.plot(x, z, 'r+', zdir='y', zs=1.5) ax.plot(y, z, 'g+', zdir='x', zs=-0.5) ax.plot(x, y, 'k+', zdir='z', zs=-1.5) ax.set_xlim([-0.5, 1.5]) ax.set_ylim([-0.5, 1.5]) ax.set_zlim([-1.5, 1.5]) plt.show()