
- 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 - 建立徽標
- 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 - 範圍滑塊
- 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 - 路徑效果
路徑效果指的是在計算機圖形學中操縱路徑(路線)的方式。 “路徑”是指使用繪圖工具建立的線條或形狀,而“路徑效果”允許您對該線條或形狀應用各種修改。
想象一下,您繪製了一條簡單的線條,使用路徑效果,您可以使該線條看起來波浪形、點狀或應用其他視覺變化,而無需手動重新繪製。這就像為建立的路徑新增特殊效果,使您的繪圖更有趣和動態。

Matplotlib 中的路徑效果
您可以使用 matplotlib 中的“path_effects”模組透過建立路徑效果來增強繪圖的視覺表示。 首先,請考慮“path_effects”模組中的“withStroke()”函式。此函式允許您為線條和標記新增筆觸或輪廓。
Matplotlib 中的路徑效果允許您透過對繪圖中的線條和形狀應用特殊的視覺效果來增強其外觀。
帶有陰影路徑效果的簡單線條
在 Matplotlib 中,建立帶有陰影的簡單線條涉及在繪圖上繪製基本線條,然後使用陰影效果對其進行增強以使其在視覺上更有趣。此效果使線條下方出現陰影,就像在繪圖表面上 tạo ra một bóng mờ tinh tế一樣。
示例
在下面的示例中,我們繪製了一條波浪線,然後使用 path_effects 模組向線條新增陰影效果。陰影效果由“灰色”筆觸組成,線上條後面 tạo ra vẻ ngoài của một cái bóng。
import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects import numpy as np # Generating data x = np.linspace(0, 10, 100) y = np.sin(x) # Creating a simple line plot fig, ax = plt.subplots() line, = ax.plot(x, y, label='Simple Line') # Adding a shadow effect to the line shadow_effect = path_effects.withStroke(linewidth=5, foreground='gray') line.set_path_effects([shadow_effect]) ax.set_title('Simple Line with Shadow Effect') plt.legend() plt.show()
輸出
以下是上述程式碼的輸出 -

帶有輪廓路徑效果的虛線
在 Matplotlib 中建立帶有輪廓路徑效果的虛線涉及在繪圖上繪製點狀線條,然後透過新增粗輪廓對其進行增強。要建立輪廓,您可以使用較粗的線寬和實線樣式在虛線上方繪製另一條線。
示例
在這裡,我們正在建立一條虛線並使用“黑色”筆觸輪廓對其進行增強,以使線條具有粗體邊框並使其脫穎而出。
import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects import numpy as np # Generating data x = np.linspace(0, 10, 100) y = np.cos(x) # Creating a dashed line plot with outline fig, ax = plt.subplots() line, = ax.plot(x, y, linestyle='dashed', label='Dashed Line') # Adding an outline effect to the line outline_effect = path_effects.withStroke(linewidth=3, foreground='black') line.set_path_effects([outline_effect]) ax.set_title('Dashed Line with Outline Effect') plt.legend() plt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出 -

粗體輪廓散點圖路徑效果
在 Matplotlib 中使用路徑效果建立粗體輪廓散點圖涉及在圖形上繪製一組點,並透過新增粗輪廓來增強每個點。
示例
在下面的示例中,我們使用隨機資料點生成散點圖。為了增強這些點的可見性,我們透過在每個散點周圍新增“黑色”筆觸和增加的“線寬”來為每個點應用粗體輪廓效果。
import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects import numpy as np # Generating data x = np.random.rand(50) y = np.random.rand(50) # Creating a scatter plot with bold outline effect fig, ax = plt.subplots() scatter = ax.scatter(x, y, label='Scatter Plot') # Adding a bold outline effect to the scatter points outline_effect = path_effects.withStroke(linewidth=3, foreground='black') scatter.set_path_effects([outline_effect]) ax.set_title('Scatter Plot with Bold Outline') plt.legend() plt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出 -

組合路徑效果
在 Matplotlib 中建立組合路徑效果圖允許我們對線條應用多種藝術增強,例如線型、標記、顏色漸變和透明度。
- 線型 - 您可以選擇各種線型選項,例如實線(' - ')、虛線(' -- ')、點線(':')等。
- 標記 - 可以新增標記以突出顯示特定資料點。常見的標記包括圓圈('o')、正方形('s')、三角形('^')等。
- 顏色漸變 - 您可以使用顏色漸變建立視覺上吸引人的線條。您可以透過指定“色圖”並使用它根據變數為線條著色來實現此目的。
- 透明度 - 為線條新增透明度可以使重疊線條更易於區分。您可以使用“alpha”引數調整透明度。
示例
現在,我們正在將三種路徑效果應用於線條:細微的陰影效果、粗體的黑色輪廓和輕微的模糊效果。結果顯示了一個組合了這些效果的線圖。
import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects import numpy as np # Generating data x = np.linspace(0, 10, 100) y = np.sin(x) # Creating a line plot fig, ax = plt.subplots() line, = ax.plot(x, y, label='Combined Effects Line') # Combine multiple path effects: Shadow, Bold Outline, and Blur shadow_effect = path_effects.withStroke(linewidth=5, foreground='cyan') outline_effect = path_effects.withStroke(linewidth=3, foreground='red') blur_effect = path_effects.withStroke(linewidth=5, foreground='magenta', alpha=0.4) # Applying the combined effects to the line line.set_path_effects([shadow_effect, outline_effect, blur_effect]) ax.set_title('Combined Path Effects Line') plt.legend() plt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出 -
