I have a numpy array with four columns and several rows. First column is my variable and three others are x
, y
and z
coordinates, respectivly:
arr= np.array([[2., 0., 0., 0.],
[1., 0., 0., 1.],
[2., 0., 1., 0.],
[3., 1., 0., 0.]])
The first column has some discrete values, e.g. it is 1
or 2
or 3
. Now, using matplotlib or any other useful library like seaborn) I want to plot these values in a 3d space created by the second, third and fourth column. For example, I want to represent 1
as red star symbols, 2
as a yellow rectangles and 3
as black squares. I do appreciate if any one help me to do so. I tried the following code but it did not give me what I want:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
x= arr[0][:,1]
y= arr[0][:,2]
X, Y = np.meshgrid(x, y)
z= arr[0][:,3]
V= arr[0][:,0]
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(45,60)
ax.plot_surface(X, Y, z, facecolors=cm.Oranges(V))
I want to have the automatic version of the following figure:
Scatter plots lead to your expected output and can easily be individualized. This example code should even work for more than just 3 cases (as long as you add marker styles and colors)