Python matplotlib 3d表面图

时间:2014-07-15 07:49:33

标签: python matplotlib

我正在尝试使用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()

1 个答案:

答案 0 :(得分:3)

我不认为matplotlib此时具有相同的功能。如果您不限于使用matplotlib,您可能需要查看mayavi及其contour3d()函数。

以下代码使用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