python三维图形渲染 地图_(python)以colormap作为4维绘制三维曲面,x,y,z的函数...

还添加了一个序列w=tan(-x*y),该序列基于该函数在灰度范围内生成彩色地图。

你可以玩cdict的建设,增加更多的颜色,但我认为灰度是一个很好的概念证明。。。

很抱歉,由于缺少最少的工作代码,我无法直接使用您的示例。from mpl_toolkits.mplot3d import Axes3D

from matplotlib import cm

import matplotlib.pyplot as plt

import numpy as np

import matplotlib.colors as mcolors

###################

def make_colormap(seq):

"""Return a LinearSegmentedColormap

seq: a sequence of floats and RGB-tuples. The floats should be increasing

and in the interval (0,1).

"""

#%

cdict = {'red': [], 'green': [], 'blue': []}

# make a lin_space with the number of records from seq.

x = np.linspace(0,1, len(seq))

#%

for i in range(len(seq)):

segment = x[i]

tone = seq[i]

cdict['red'].append([segment, tone, tone])

cdict['green'].append([segment, tone, tone])

cdict['blue'].append([segment, tone, tone])

#%

return mcolors.LinearSegmentedColormap('CustomMap', cdict)

#############################

n_angles = 36

n_radii = 8

# An array of radii

# Does not include radius r=0, this is to eliminate duplicate points

radii = np.linspace(0.125, 1.0, n_radii)

# An array of angles

angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)

# Repeat all angles for each radius

angles = np.repeat(angles[...,np.newaxis], n_radii, axis=1)

# Convert polar (radii, angles) coords to cartesian (x, y) coords

# (0, 0) is added here. There are no duplicate points in the (x, y) plane

x = np.append(0, (radii*np.cos(angles)).flatten())

y = np.append(0, (radii*np.sin(angles)).flatten())

# Pringle surface

z = np.sin(-x*y)

w = np.tan(-x*y)

colors = make_colormap(w)

fig = plt.figure()

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

ax.plot_trisurf(x, y, z, cmap=colors, linewidth=0.2)

plt.show()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值