Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: AttributeError in plotting a 3d surface

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()
like image 816
Soyol Avatar asked Feb 28 '26 13:02

Soyol


1 Answers

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()
like image 74
Soyol Avatar answered Mar 03 '26 04:03

Soyol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!