3

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()
1
  • w1 is defined before, and is a array of values with same dimension as X, Z...I checked by shape() Commented Mar 19, 2016 at 2:11

2 Answers 2

6

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()
Sign up to request clarification or add additional context in comments.

Comments

0
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()

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.