Traceback most recent call last File Ethreepicturethreepicturepy line 20 in module axplot_surfaceX Y Z cmap=Blues File Ethreepicturevenvlibsite-packagesmpl_toolkitsmplot3daxes3dpy line 1569 in pl
This error occurs when the variable Z is a float instead of a NumPy array or a list. The plot_surface function in the mpl_toolkits.mplot3d.axes3d module expects Z to be a 2D array.
To fix this error, make sure that the variable Z is a 2D array or a list of lists (2D list). You can use the numpy.array function to convert a list or a 1D array to a 2D array.
Here's an example of how to fix the error:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# Generate data for X, Y, and Z
X = np.arange(-5, 5, 0.1)
Y = np.arange(-5, 5, 0.1)
X, Y = np.meshgrid(X, Y)
Z = np.sin(np.sqrt(X**2 + Y**2))
# Create a 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the surface
ax.plot_surface(X, Y, Z, cmap='Blues')
# Show the plot
plt.show()
In this example, Z is generated using the NumPy sin function applied to the square root of the sum of squares of X and Y arrays. The X and Y arrays are generated using the arange function and then converted to 2D arrays using the meshgrid function. Finally, the plot_surface function is called with the correct X, Y, and Z arrays to plot the surface
原文地址: https://www.cveoy.top/t/topic/hGjc 著作权归作者所有。请勿转载和采集!