
- Matplotlib基礎
- Matplotlib - 首頁
- Matplotlib - 簡介
- Matplotlib - 與Seaborn對比
- Matplotlib - 環境搭建
- Matplotlib - Anaconda發行版
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - 簡單繪圖
- Matplotlib - 儲存圖形
- Matplotlib - 標記
- Matplotlib - 圖形
- Matplotlib - 樣式
- Matplotlib - 圖例
- Matplotlib - 顏色
- Matplotlib - 顏色對映
- Matplotlib - 顏色對映歸一化
- Matplotlib - 選擇顏色對映
- Matplotlib - 顏色條
- Matplotlib - 文字
- Matplotlib - 文字屬性
- Matplotlib - 子圖示題
- Matplotlib - 圖片
- Matplotlib - 圖片蒙版
- Matplotlib - 註釋
- Matplotlib - 箭頭
- Matplotlib - 字型
- Matplotlib - 什麼是字型?
- 全域性設定字型屬性
- Matplotlib - 字型索引
- Matplotlib - 字型屬性
- Matplotlib - 比例尺
- Matplotlib - 線性與對數比例尺
- Matplotlib - 對稱對數和Logit比例尺
- Matplotlib - LaTeX
- Matplotlib - 什麼是LaTeX?
- Matplotlib - LaTeX用於數學表示式
- Matplotlib - 在註釋中使用LaTeX文字格式
- Matplotlib - PostScript
- 啟用註釋中的LaTeX渲染
- Matplotlib - 數學表示式
- Matplotlib - 動畫
- Matplotlib - 圖形物件
- Matplotlib - 使用Cycler進行樣式設定
- Matplotlib - 路徑
- Matplotlib - 路徑效果
- Matplotlib - 變換
- Matplotlib - 刻度和刻度標籤
- Matplotlib - 弧度刻度
- Matplotlib - 日期刻度
- Matplotlib - 刻度格式化器
- Matplotlib - 刻度定位器
- Matplotlib - 基本單位
- Matplotlib - 自動縮放
- Matplotlib - 反轉座標軸
- Matplotlib - 對數座標軸
- Matplotlib - Symlog
- Matplotlib - 單位處理
- Matplotlib - 帶單位的橢圓
- Matplotlib - 脊柱
- Matplotlib - 座標軸範圍
- Matplotlib - 座標軸比例尺
- Matplotlib - 座標軸刻度
- Matplotlib - 座標軸格式化
- Matplotlib - Axes 類
- Matplotlib - 雙座標軸
- Matplotlib - Figure 類
- Matplotlib - 多圖
- Matplotlib - 網格
- Matplotlib - 面向物件介面
- Matplotlib - PyLab 模組
- Matplotlib - Subplots() 函式
- Matplotlib - Subplot2grid() 函式
- Matplotlib - 定點陣圖形物件
- Matplotlib - 手動等高線
- Matplotlib - 座標報告
- Matplotlib - AGG 濾鏡
- Matplotlib - 帶狀框
- Matplotlib - 填充螺旋線
- Matplotlib - Findobj 演示
- Matplotlib - 超連結
- Matplotlib - 圖片縮圖
- Matplotlib - 使用關鍵字繪圖
- Matplotlib - 建立Logo
- Matplotlib - 多頁PDF
- Matplotlib - 多程序
- Matplotlib - 列印標準輸出
- Matplotlib - 複合路徑
- Matplotlib - Sankey 類
- Matplotlib - MRI與EEG
- Matplotlib - 樣式表
- Matplotlib - 背景顏色
- Matplotlib - Basemap
- Matplotlib 事件處理
- Matplotlib - 事件處理
- Matplotlib - 關閉事件
- Matplotlib - 滑鼠移動
- Matplotlib - 點選事件
- Matplotlib - 滾動事件
- Matplotlib - 按鍵事件
- Matplotlib - 選擇事件
- Matplotlib - 透鏡
- Matplotlib - 路徑編輯器
- Matplotlib - 多邊形編輯器
- Matplotlib - 定時器
- Matplotlib - Viewlims
- Matplotlib - 縮放視窗
- Matplotlib 小部件
- Matplotlib - 游標小部件
- Matplotlib - 帶註釋的游標
- Matplotlib - 按鈕小部件
- Matplotlib - 複選框
- Matplotlib - 套索選擇器
- Matplotlib - 選單小部件
- Matplotlib - 滑鼠游標
- Matplotlib - 多游標
- Matplotlib - 多邊形選擇器
- Matplotlib - 單選按鈕
- Matplotlib - RangeSlider
- Matplotlib - 矩形選擇器
- Matplotlib - 橢圓選擇器
- Matplotlib - 滑塊小部件
- Matplotlib - 區間選擇器
- Matplotlib - 文字框
- Matplotlib 繪圖
- Matplotlib - 條形圖
- Matplotlib - 直方圖
- Matplotlib - 餅圖
- Matplotlib - 散點圖
- Matplotlib - 箱線圖
- Matplotlib - 小提琴圖
- Matplotlib - 等高線圖
- Matplotlib - 3D繪圖
- Matplotlib - 3D等高線
- Matplotlib - 3D線框圖
- Matplotlib - 3D曲面圖
- Matplotlib - 矢羽圖
- Matplotlib 有用資源
- Matplotlib - 快速指南
- Matplotlib - 有用資源
- Matplotlib - 討論
Matplotlib - 3D等高線
3D等高線指的是在三維空間中顯示物體形狀和高度的線或曲線。這些等高線幫助我們理解物體的不同部分有多高或多低。它們通常用於地理、工程和藝術等領域,以更詳細的方式表示物體的形狀。
例如,如果你有一座山,它的3D等高線將顯示從各個方向看到的斜坡、山谷和山峰。同樣,如果你有一個動物雕塑,它的3D等高線將從各個角度描述其身體、頭部和四肢的形狀。

Matplotlib中的3D等高線
在Matplotlib中,3D等高線表示三維物體的表面。它允許你透過提供表示x、y和z座標的資料點來建立3D等高線圖。這些點定義了你想要視覺化的物體的形狀。然後,Matplotlib可以生成等高線或曲面來表示你的3D資料的等高線。
你可以使用“mpl_toolkits.mplot3d”模組中的contour3D()函式在Matplotlib中建立3D等高線。此函式接受三個座標——X、Y和Z作為陣列,並在X和Y座標之間繪製一條線,以顯示沿z軸的三維物體的輪廓或高度變化。
讓我們從繪製一個基本的3D等高線開始。
基本的3D等高線
Matplotlib中的基本3D等高線就像在地圖上繪製海拔線,但在三維空間中。它使用X、Y和Z軸顯示錶面在不同點的高度變化。
示例
在下面的示例中,我們首先繪製X和Y座標來建立一個基本的3D等高線。然後,我們取X和Y的正弦和餘弦值的和來獲得海拔變化。生成的圖顯示了形狀的輪廓,Z軸上有不同的高度。
import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D # Creating data x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(X) + np.cos(Y) # Creating a 3D plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Plotting the 3D contour ax.contour3D(X, Y, Z, 50, cmap='viridis') # Customizing the plot ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_zlabel('Z-axis') ax.set_title('Basic 3D Contour Plot') # Displaying the plot plt.show()
輸出
以下是上述程式碼的輸出。

引數化3D等高線
Matplotlib中的引數化3D等高線使用三維中的數學引數表示不同高度的形狀輪廓。等高線不僅由X、Y和Z座標的變化定義,還由引數的變化定義。
示例
在這裡,我們基於三維物體的尺寸(R)、厚度(r)和初始座標(u, v)來引數化X、Y和Z座標。生成的圖建立一個甜甜圈形狀的3D等高線。
import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D # Parametric equations for a torus def torus_parametric(u, v, R=1, r=0.3): x = (R + r * np.cos(v)) * np.cos(u) y = (R + r * np.cos(v)) * np.sin(u) z = r * np.sin(v) return x, y, z # Creating data u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, 2 * np.pi, 100) U, V = np.meshgrid(u, v) X, Y, Z = torus_parametric(U, V) # Creating a 3D plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Plotting the parametric 3D contour ax.contour3D(X, Y, Z, 50, cmap='plasma') # Customizing the plot ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_zlabel('Z-axis') ax.set_title('Parametric 3D Contour Plot (Torus)') # Displaying the plot plt.show()
輸出
執行上述程式碼後,我們將得到以下輸出。

來自不規則資料的3D等高線
在Matplotlib中,來自不規則資料的3D等高線顯示資料點隨機的三維表面的輪廓。在這種型別的等高線中,我們透過基於X、Y和Z值估計值來計算缺失的資料點。
示例
以下示例建立了來自不規則資料的3D等高線。在這裡,我們計算缺失的資料點,並使用已知資料點對其進行線性插值。這產生了平滑且連續的3D等高線作為結果。
import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D from scipy.interpolate import griddata # Creating irregularly spaced data np.random.seed(42) x = np.random.rand(100) y = np.random.rand(100) z = np.sin(x * y) # Creating a regular grid xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100) xi, yi = np.meshgrid(xi, yi) # Combining irregular data onto the regular grid zi = griddata((x, y), z, (xi, yi), method='linear') # Creating a 3D plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Plotting the 3D contour from irregular data on the regular grid ax.contour3D(xi, yi, zi, 50, cmap='viridis') # Customizing the plot ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_zlabel('Z-axis') ax.set_title('3D Contour Plot from Irregular Data') # Displaying the plot plt.show()
輸出
執行上述程式碼後,我們將得到以下輸出。

3D等高線中的等高線
在Matplotlib中,3D等高線中的等高線以三維方式直觀地表示物體的3D等高線及其等高線。等高線表示3D等高線的斜率,並在XY平面上表示,因為它們沒有任何Z值(沒有深度)。“contour()”函式用於顯示物體的等高線。
示例
現在,我們正在建立一個物體的3D等高線和等高線。我們在z軸上繪製3D等高線,在XY平面上繪製等高線。生成的圖顯示了沿z軸的物體的輪廓及其在XY平面上的斜率。
import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D # Creating data x = np.linspace(-5, 5, 100) y = np.linspace(-5, 5, 100) X, Y = np.meshgrid(x, y) Z = np.sin(np.sqrt(X**2 + Y**2)) # Creating a 3D plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # Plotting the 3D contour ax.contour3D(X, Y, Z, 50, cmap='plasma') # Adding contour lines on the XY plane ax.contour(X, Y, Z, zdir='z', offset=np.min(Z), cmap='plasma') # Customizing the plot ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') ax.set_zlabel('Z-axis') ax.set_title('3D Contour Plot with Contour Lines') # Displaying the plot plt.show()
輸出
執行上述程式碼後,我們將得到以下輸出。
