線框圖採用值網格並將其投影到指定的三維表面上,並且可以使得到的三維形式非常容易視覺化。plot_wireframe()
函式用於此目的 -
#! /usr/bin/env python
#coding=utf-8
import matplotlib.pyplot as plt
import numpy as np
import math
import seaborn as sns
plt.rcParams['font.sans-serif'] = ['SimHei'] # 步驟一(替換sans-serif字型)
plt.rcParams['axes.unicode_minus'] = False # 原文出自【易百教學】,商業轉載請聯絡作者獲得授權,非商業請保留原文連結:
from mpl_toolkits import mplot3d
def f(x, y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
def f(x, y):
return np.sin(np.sqrt(x ** 2 + y ** 2))
x = np.linspace(-6, 6, 30)
y = np.linspace(-6, 6, 30)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_wireframe(X, Y, Z, color='black')
ax.set_title('線框圖')
plt.show()
執行上面範例程式碼,得到以下結果 -