Sample data like this :
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d as Axes3D
from matplotlib import cm
import numpy as np
x = np.linspace(1,4,10)
y = np.linspace(3,4,10)
z = np.linspace(10,20,7)
data = np.random.rand(10,7)
and custom plot like this:
xx = np.ones((10,7))
yy = np.ones((10,7))
zz = np.ones((10,7))
for i in range(7):
xx[:,i] = x
yy[:,i] = y
for i in range(10):
zz[i,:] = z
And wireframe like this :
When I try this to get surface color:
ax = plt.figure().add_subplot(111,projection = '3d')
ax.plot_surface(xx,yy,zz,facecolor = cm.coolwarm(data))
plt.show()
Error like this :
ValueError: RGBA sequence should have length 3 or 4
I can't figure out why this is fail. I need this custom plot to replace Meshgrid (truly need this plot as my output). Can anyone solve this problem? Ty
CodePudding user response:
colors= cm.coolwarm(data)
ax.plot_surface(xx,yy,zz,cmap = cm.coolwarm, facecolors =colors)
You can read more about this at
CodePudding user response:
ax.plot_surface (xx, yy, zz, cmap = cm.coolwarm)
This will not generate an error. But what is the ultimate result you want to get? The surface painted in colors according to the values of the variable?