Python Matplotlib 3D表面图 [英] Python matplotlib 3d surface plot

查看:108
本文介绍了Python Matplotlib 3D表面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to convert an equation for a surface plot written for mathematica (image and script below) to a python script using matplotlib. There are only a handful of examples of surface plots on the web.

对于许多尝试中我无法正常工作的帮助,将不胜感激

Help would be appreciated for my non functioning 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()

推荐答案

我现在不认为matplotlib具有等效功能.如果您不限于使用matplotlib,则可能要看一下 mayavi 和其 contour3d() 函数

I don't think that matplotlib has an equivalent function at this point. If you are not restricted to using matplotlib, you might want to take a look at mayavi and its contour3d()function.

以下代码使用 mayavi 生成与您的示例类似的图.我不确定是否可以添加线框轮廓.

The following code produces a similar plot to your example using mayavi. I am not sure if it's possible to add the wireframe outline however.

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

这篇关于Python Matplotlib 3D表面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆