python 绘制二维曲面_用python绘制曲面[复制]
我試圖繪制一些數(shù)據(jù),其中包括4個變量。我用了兩種方法,一種是散點(diǎn)圖,另一種是曲面圖。問題是當(dāng)我使用surface時,數(shù)據(jù)丟失了。我想這和顏色設(shè)置有關(guān)。
對于散點(diǎn)圖,我使用:
def scatter3d(x,y,z, cs, colorsMap='jet'):
cm = plt.get_cmap(colorsMap)
cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(x, y, z,c=scalarMap.to_rgba(cs))
ax.set_xlabel('Thita1')
ax.set_ylabel('Thita2')
ax.set_zlabel('Fairness (%)')
scalarMap.set_array(cs)
fig.colorbar(scalarMap,label='Error Rate (%)')
plt.show()
我想把它轉(zhuǎn)換成一個曲面圖,使用這個:
def surfacePlot(x,y,z, cs, colorsMap='jet'):
cm = plt.get_cmap(colorsMap)
cNorm = matplotlib.colors.Normalize(vmin=min(cs), vmax=max(cs))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=cm)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, facecolors=scalarMap.to_rgba(cs))
ax.set_xlabel('Thita1')
ax.set_ylabel('Thita2')
ax.set_zlabel('Fairness')
scalarMap.set_array(cs)
fig.colorbar(scalarMap,label='Error Rate (%)')
plt.show()
但是,這將導(dǎo)致空網(wǎng)格:
盡管軸已從矢量中接收到最小值和最大值,但這些點(diǎn)已丟失。我做錯什么了?
總結(jié)
以上是生活随笔為你收集整理的python 绘制二维曲面_用python绘制曲面[复制]的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python中left是什么意思_Pyt
- 下一篇: 怎么把图片四角去掉_端午“粽子”怎么做,