I\'m currently conducting some 3D plots in Python 2.7.9 using Matplotlib 1.4.3. (Sorry, my rating does not allow me to attach pictures yet). I would like to switch the data of
You have to use facecolors
instead of cmap
and for calling colorbar
we have to create a mappable object using ScalarMappable
. This code here worked for me.
import pylab as py
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
import matplotlib as mpl
from matplotlib import cm
# Create figure and get data
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
N = (Z-Z.min())/(Z-Z.min()).max()
# Plot surface and colorbar
c1 = ax.plot_surface(Z, Y, X, rstride=8, cstride=8, alpha=0.9, facecolors=cm.PiYG_r(N))
m = cm.ScalarMappable(cmap=cm.PiYG_r)
m.set_array(X)
cbar = plt.colorbar(m)
# Labels
ax.set_xlabel('X')
ax.set_xlim3d(-100, 100)
ax.set_ylabel('Y')
ax.set_ylim3d(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim3d(-40, 40)
plt.show()