Python matplotlib 3D surface

I am trying to convert an equation for a surface graph written for math (image and script below) to a python script using matplotlib. There are only a few examples of surface graphs on the Internet.

enter image description here

Help will be appreciated for my broken one of many attempts

from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.linspace(2,-2) y = np.linspace(2,-2) z = np.linspace(2,-2) surfx = -1 * (pow(y, 10) + pow(z, 10) - 100) surfy = -1 * (pow(x, 10) + pow(z, 10) - 100) surfz = -1 * (pow(x, 10) + pow(y, 10) - 100) ax.plot_surface(surfx,surfy,surfz, rstride=4, cstride=4, color='b') plt.show() 
0
source share
1 answer

I do not think matplotlib has an equivalent function at this point. If you are not limited to using matplotlib, you can take a look at mayavi and contour3d() .

The following code creates a similar plot in your example using mayavi. I'm not sure if you can add a wireframe outline.

 import numpy as np from mayavi import mlab x, y, z = np.ogrid[-2:2:25j, -2:2:25j, -2:2:25j] s = np.power(x, 10) + np.power(y, 10) + np.power(z, 10) - 100 mlab.figure(bgcolor=(1,1,1)) mlab.contour3d(s, contours=[2], color=(.5,.5,.5), transparent=True, opacity=.5) ax = mlab.axes(nb_labels=5, ranges=(-2,2,-2,2,-2,2)) ax.axes.property.color = (0,0,0) ax.axes.axis_title_text_property.color = (0,0,0) ax.axes.axis_label_text_property.color = (0,0,0) ax.axes.label_format='%.0f' mlab.show() 

mayavi contour3d plot

+2
source

Source: https://habr.com/ru/post/974335/


All Articles