1""" 2===================== 33D surface (colormap) 4===================== 5 6Demonstrates plotting a 3D surface colored with the coolwarm colormap. 7The surface is made opaque by using antialiased=False. 8 9Also demonstrates using the LinearLocator and custom formatting for the 10z axis tick labels. 11""" 12 13import matplotlib.pyplot as plt 14from matplotlib import cm 15from matplotlib.ticker import LinearLocator 16import numpy as np 17 18fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) 19 20# Make data. 21X = np.arange(-5, 5, 0.25) 22Y = np.arange(-5, 5, 0.25) 23X, Y = np.meshgrid(X, Y) 24R = np.sqrt(X**2 + Y**2) 25Z = np.sin(R) 26 27# Plot the surface. 28surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, 29 linewidth=0, antialiased=False) 30 31# Customize the z axis. 32ax.set_zlim(-1.01, 1.01) 33ax.zaxis.set_major_locator(LinearLocator(10)) 34# A StrMethodFormatter is used automatically 35ax.zaxis.set_major_formatter('{x:.02f}') 36 37# Add a color bar which maps values to colors. 38fig.colorbar(surf, shrink=0.5, aspect=5) 39 40plt.show() 41 42 43############################################################################# 44# 45# .. admonition:: References 46# 47# The use of the following functions, methods, classes and modules is shown 48# in this example: 49# 50# - `matplotlib.pyplot.subplots` 51# - `matplotlib.axis.Axis.set_major_formatter` 52# - `matplotlib.axis.Axis.set_major_locator` 53# - `matplotlib.ticker.LinearLocator` 54# - `matplotlib.ticker.StrMethodFormatter` 55