簡體   English   中英

Python Matplotlib 3D表面圖

[英]Python matplotlib 3d surface plot

我正在嘗試使用matplotlib將為mathematica(下面的圖像和腳本)編寫的表面圖的方程式轉換為python腳本。 網上只有很少的表面圖示例。

在此處輸入圖片說明

對於許多嘗試中我無法正常工作的幫助,我們將不勝感激

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()函數。

以下代碼與使用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 outline3d圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM