Reputation: 1051
I would like to add 3D plot in matplotlib 1.5.1 to the existing set of 2D plots (subplots). 2D plots work fine w/o 3D, but when I add 3D I'm getting an error that 'module' object has no attribute 'plot_surface'. I'd like to keep the code simple so I apply all commands to plt without creating new figure(there is also a way of adding labels with set_xlabel) which makes things ambiguous. The first 3 plots are simple 2D plots and the last is 3D.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
y1 = u.nodes.concentration
x1 = u.nodes.x
plt.figure(figsize=(20, 10))
plt.subplot(221)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x1, y1, '-b')
# Inhibitor plt
y2 = z.nodes.concentration
x2 = z.nodes.x
plt.subplot(222)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x2, y2, '-r')
# Modulator plt
y3 = v.nodes.concentration
x3 = v.nodes.x
plt.subplot(223)
plt.title('Profile')
plt.xlabel('Range')
plt.ylabel('Concentration')
plt.plot(x3, y3, '-g')
#3D plot
plt.subplot(224, projection='3d')
# Grab data.
xx = u_fft_x_norm
yy = [i*time_period for i in xrange(1, times)]
zz = u_timespace
XX, YY = np.meshgrid(xx, yy)
ZZ = zz
# Plot a basic wireframe.
plt.plot_surface(XX, YY, ZZ, rstride=20, cstride=20)
plt.xlabel('Space')
plt.ylabel('Time')
plt.zlabel('Value')
plt.title('Profile')
Upvotes: 1
Views: 3100
Reputation: 339775
I guess the error is self-explanatory. pyplot
does not have a plot_surface command. There is also no indication that it should. Looking at all examples you find, plot_surface
is an attribute of an axes.
ax = plt.subplot(224, projection='3d')
ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)
Upvotes: 1