我试图根据z值给线框图上色。我在网上找不到任何代码示例。
下面是一个具有我想要的颜色的曲面图和一个无法在线条上获得颜色的线框图的示例:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt

# some numbers for the data
P=12000 #W
Q=1     #kg/s
DT=3    #K
cp=4169.32  #J/kgK

dDT=np.logspace(-2,0,20,endpoint=True)
dQ=Q*np.logspace(-3,-1,20,endpoint=True)

# the plotting data
m1,m2=np.meshgrid(dDT,dQ)
err=cp*np.sqrt((m1*Q)**2+(m2*DT)**2)/P

# the wiremesh plot that i need fixed
fig=plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_wireframe(m1, m2, err, color=err/err.max(),cmap='jet')
ax.set_xlabel('dDT')
ax.set_ylabel('DQ')
ax.set_zlabel('relative error')

# the surface plot that has the colors i want
fig = plt.figure()
ax = fig.gca(projection='3d')

surf = ax.plot_surface(m1, m2, err,rstride=1,  cstride=1, cmap=cm.jet,
    linewidth=0.1, antialiased=False)

fig.colorbar(surf, shrink=0.5, aspect=5)

ax.set_xlabel('dDT')
ax.set_ylabel('DQ')
ax.set_zlabel('relative error')
plt.show()

谢谢你的帮助!

最佳答案

使用plot_线框时,每条线只能有一种颜色。
相反,您可以使用Plot_Surface。
要让Plot_Surface设置边缘颜色,需要为其指定面颜色。
然后您可以将facecolors的alpha设置为零。

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

X, Y, Z = axes3d.get_test_data(0.2)

# Normalize to [0,1]
norm = plt.Normalize(Z.min(), Z.max())
colors = cm.viridis(norm(Z))
rcount, ccount, _ = colors.shape

fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, rcount=rcount, ccount=ccount,
                       facecolors=colors, shade=False)
surf.set_facecolor((0,0,0,0))
plt.show()

python - matplotlib中的彩色线框图-LMLPHP

关于python - matplotlib中的彩色线框图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15134004/

10-09 06:10