python3d曲面图_Python中3D表面图的颜色

I'm using following line for plotting a 3D surface:

surf = ax3.plot_surface(X, Y, Z, rstride=1, cstride=1, alpha=0.5, linewidth=0, cmap=cm.jet,antialiased=True)

Now the color comes very nice, although a bit scaly appearance, though fine.

But I want to change the surface color w.r.t. another data, stored in list as:

m = [104.48, 111.73,109.93,139.95,95.05,150.49,136.96,157.75]

I was trying with:

norm = cls.Normalize() # Norm to map the 'm' values to [0,1]

norm.autoscale(m)

cmap = cm.ScalarMappable(norm, 'jet')

surf = ax3.plot_surface(X, Y, Z, rstride=5, cstride=5, alpha=0.5, linewidth=0, color=cmap.to_rgba(m), antialiased=True)

But this is raising an error as cmap.to_rgba takes 1D arrays only.

Any suggestions on how can I be able to change the colormap of the surface would be highly appreciated.

解决方案

Well, it looks awful but I think you can adapt it:

from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

from matplotlib.ticker import LinearLocator, FormatStrFormatter

import matplotlib.pyplot as plt

import numpy as np

fig = plt.figure()

ax = fig.gca(projection='3d')

X = np.arange(-5, 5, 0.25)

Y = np.arange(-5, 5, 0.25)

X, Y = np.meshgrid(X, Y)

R = np.sqrt(X**2 + Y**2)

Z = np.sin(R)

my_col = cm.jet(np.random.rand(Z.shape[0],Z.shape[1]))

surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors = my_col,

linewidth=0, antialiased=False)

ax.set_zlim(-1.01, 1.01)

I would not use jet but some linear colormap like cubehelix. You can trick the eye easily using the wrong colormap (one of many posts on that topic)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值