Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting the projection of 3D plot in three planes using contours

I have a three columns catalogue of data and I would like to make a 3D plot of them plus the projection of each axis as a projected contour in the the plane of the other two axises. So far I could make the 3D plot using matplotlib which still doesn't show anything from the properties of the data.

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from numpy import * 
data=loadtxt('test.cat')
X=data[:,0]
Y=data[:,1]
Z=data[:,2]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(X, Y, Z, c='r', marker='.')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

How could I plot the projection of the data in each plane with colorbar as well?

like image 308
Dalek Avatar asked Nov 04 '14 16:11

Dalek


People also ask

How do you plot in 3D contour?

To plot 3D contour we will use countour3() to plot different types of 3D modules. Syntax: contour3(X,Y,Z): Specifies the x and y coordinates for the values in Z. contour3(Z): Creates a 3-D contour plot containing the isolines of matrix Z, where Z contains height values on the x-y plane.

Which function is used to draw 3D contour plot?

contour3D() function creates three-dimensional contour plot. It requires all the input data to be in the form of two-dimensional regular grids, with the Z-data evaluated at each point. Here, we will show a three-dimensional contour diagram of a three-dimensional sinusoidal function.


1 Answers

hmm, indeed, difficult data to display. Maybe creating some slices along one axis and creating certain number 2D plots would be best. However 3D plots are fancy. I played a bit with the data resulting in one 3D plot as you did and a separate plot with the projections.

  • The colors of the points are according the missing axis
  • Added transparency to give an idea of density
  • Kept axes of both plots the same

enter image description hereenter image description here

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

data = np.loadtxt('test.cat', skiprows=1)

X=data[:,0]
Y=data[:,1]
Z=data[:,2]

plt.figure()
ax1 = plt.subplot(111,  projection='3d')

ax1.scatter(X, Y, Z, c='b', marker='.', alpha=0.2)
ax1.set_xlabel('X - axis')
ax1.set_ylabel('Y - axis')
ax1.set_zlabel('Z - axis')

plt.figure()
ax2 = plt.subplot(111,  projection='3d')

plt.hot()

cx = np.ones_like(X) * ax1.get_xlim3d()[0]
cy = np.ones_like(X) * ax1.get_ylim3d()[1]
cz = np.ones_like(Z) * ax1.get_zlim3d()[0]

ax2.scatter(X, Y, cz, c=Z,  marker='.', lw=0, alpha=0.2)
ax2.scatter(X, cy, Z, c=-Y, marker='.', lw=0, alpha=0.2)
ax2.scatter(cx, Y, Z, c=X,  marker='.', lw=0, alpha=0.2)
ax2.set_xlim3d(ax1.get_xlim3d())
ax2.set_ylim3d(ax1.get_ylim3d())
ax2.set_zlim3d(ax1.get_zlim3d())
ax2.set_xlabel('X - axis')
ax2.set_ylabel('Y - axis')
ax2.set_zlabel('Z - axis')
like image 185
Jan Kuiken Avatar answered Oct 30 '22 13:10

Jan Kuiken