Python matplotlib三维曲面p

2024-06-26 12:46:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用matplotlib将为mathematica编写的曲面图的方程式(下面的图像和脚本)转换为python脚本。在网上只有少数几个表面图的例子。在

enter image description here

如果我在许多尝试中没有发挥作用,我们将不胜感激

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

Tags: import脚本matplotlibasnpfigpltax
1条回答
网友
1楼 · 发布于 2024-06-26 12:46:50

我不认为matplotlib在这一点上有一个等价的函数。如果您不局限于使用matplotlib,那么您可能需要看看mayavi及其^{}函数。在

下面的代码生成一个与使用mayavi的示例类似的绘图。我不确定是否可以添加线框轮廓,但。在

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

相关问题 更多 >