简体   繁体   中英

3D Plot Surface With Custom Data

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

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM