Reputation: 793
I am trying to plot a 3d surface by having coordinates of x,y and values as w1. I have checked the dimensions by shape(), they match. but I receive the error that "AttributeError: 'module' object has no attribute 'plot_surface'"
Code:
import numpy as np
import math
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
. . .
x = np.arange(xmin, xmax+dx, dx)
z = np.arange(zmin, zmax+dz, dz)
X, Z = np.meshgrid(x, z)
#print X.shape, Z.shape, w1.shape
plt.plot_surface(X, Z, w1)
plt.show()
Upvotes: 3
Views: 15670
Reputation: 1
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Define the region bounded by y = sqrt(x) and y = 0
x = np.linspace(0, 3, 100)
y = np.sqrt(x)
# Create a 3D figure
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Revolve about the x-axis
ax.plot(x, y, zs=0, label='y = sqrt(x)')
ax.fill_between(x, y, 0, alpha=0.2)
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_title('Solid Revolved about the x-axis')
ax.legend()
plt.show()
Upvotes: 0
Reputation: 793
This way it worked for me:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.arange(xmin, xmax+dx, dx)
z = np.arange(zmin, zmax+dz, dz)
X, Z = np.meshgrid(x, z)
ax.plot_surface(X, Z, w1)
plt.show()
Upvotes: 6