还添加了一个序列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()