Z contains NaN values. This may result in rendering artifacts.
Stack Overflow用户:发布于 2014-04-24 02:08:37
在调用vmin
时设置plot_surface
和vmax
参数。这些值会影响彩色条映射的最小值和最大值。
import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as axes3d def peaks(x, y): return x*np.sin(y) fig = plt.figure() ax = fig.add_subplot(1, 1, 1, projection='3d') X, Y = np.meshgrid(np.linspace(-3, 3, 100), np.linspace(-3, 3, 100)) Z = peaks(X, Y) Z[X+Y>3] = np.nan surf = ax.plot_surface(X, Y, Z, alpha=0.3, cmap=plt.cm.jet, vmin=np.nanmin(Z), vmax=np.nanmax(Z)) cbar = plt.colorbar(surf) plt.show()