write the code for 3 d graph plot on phython
- User
write the code for 3 d graph plot on phython
- Assistant
Certainly! Here's an example code for plotting a 3D graph using Python and the
matplotliblibrary:pythonimport numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Create some data points for the x, y, and z axes x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = 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='viridis') # Set labels and title ax.set_xlabel('X Axis') ax.set_ylabel('Y Axis') ax.set_zlabel('Z Axis') ax.set_title('3D Plot') # Display the plot plt.show()