python不带颜色的图形_python – matplotlib plot_surface带有非线性颜色图的3D绘图

问题是网格不是很密集.凹凸由单个像素组成.因此网格中有4个单元格,其中3个单元格的左下角为0,因此根据其值不会接收到不同的颜色.只有实际上是凹凸的一个像素才会变色.

from mpl_toolkits.mplot3d import axes3d

import matplotlib.pyplot as plt

from matplotlib import cm

import numpy as np

X,Y = np.meshgrid(np.arange(-99,-90), np.arange(-200,250,50))

Z = np.zeros_like(X)

Z[:,0] = 100.

Z[4][7] = 10

norm = plt.Normalize(Z.min(),Z.min()+10 )

colors = cm.viridis(norm(Z))

fig = plt.figure()

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

surf = ax.plot_surface(X, Y, Z, facecolors=colors, shade=False)

surf.set_facecolor((0,0,0,0))

plt.show()

现在,您可以展开绘图的彩色部分,例如使用scipy.ndimage.grey_dilation,使得相邻的所有像素也变为黄色.

from scipy import ndimage

C = ndimage.grey_dilation(Z, size=(2,2), structure=np.ones((2, 2)))

norm = plt.Normalize(Z.min(),Z.min()+10 )

colors = cm.viridis(norm(C))

你可能感兴趣的:(python不带颜色的图形)