
- 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 - Quiver 圖
- Matplotlib 有用資源
- Matplotlib - 快速指南
- Matplotlib - 有用資源
- Matplotlib - 討論
Matplotlib - 錨定藝術家
在 Matplotlib 中,**藝術家 (Artist)** 是一個基本物件,它表示繪圖中幾乎所有元件。無論是線條、文字、軸還是任何其他圖形元素,Matplotlib 繪圖中的所有內容都是藝術家 (Artist) 的例項或派生自藝術家 (Artist) 類。
**錨定藝術家 (Anchored Artists)** 是一種特殊的自定義藝術家,可以錨定到繪圖上的特定位置。它們可用於添加註釋、箭頭和其他錨定到特定點或區域的自定義元素。
請參閱以下示例以供參考 -

在上圖中,您可以觀察到文字框、圓形和尺寸條都錨定在繪圖上的特定位置。
Matplotlib 中的錨定藝術家
在 Matplotlib 中有兩個模組提供錨定藝術家,它們是 -
Matplotlib.offsetbox
Mpl_toolkits.axes_grid1.anchored_artists
matplotlib.offsetbox 模組
此模組提供諸如 **AnchoredOffsetbox** 和 **AnchoredText** 之類的類,允許您相對於父軸或特定錨點錨定任意藝術家或文字。這些可用於更通用的註釋和裝飾。
示例
現在,讓我們使用 **matplotlib.offsetbox** 模組中的 **AnchoredText** 類在繪圖上的特定位置實現兩個**錨定文字框**。
import matplotlib.pyplot as plt from matplotlib.offsetbox import AnchoredText # Create a figure and axis fig, ax = plt.subplots(figsize=(7, 4)) # Anchored Text Box 1 at = AnchoredText("Anchored text-box 1", loc='upper left', prop=dict(size=10), frameon=True) at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") ax.add_artist(at) # Anchored Text Box 2 at2 = AnchoredText("Anchored text-box 2", loc='center', prop=dict(size=16), frameon=True, bbox_to_anchor=(0.5, 0.5), bbox_transform=ax.transAxes) at2.patch.set_boxstyle("round,pad=0.,rounding_size=0.5") ax.add_artist(at2) # Display the plot plt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出 -

mpl_toolkits.axes_grid1.anchored_artists 模組
此模組提供諸如 **AnchoredDirectionArrows**、**AnchoredAuxTransformBox**、**AnchoredDrawingArea** 和 **AnchoredSizeBar** 之類的專用錨定藝術家。每個類用於不同的目的。
讓我們看看每個類的用法 -
**AnchoredAuxTransformBox** - 一個帶有轉換座標的錨定容器。
**AnchoredDirectionArrows** - 繪製兩個垂直箭頭以指示方向。
**AnchoredDrawingArea** - 一個具有固定大小和可填充 DrawingArea 的錨定容器。
**AnchoredSizeBar** - 繪製一個水平比例尺,下方帶有居中對齊的標籤。
示例
此示例演示瞭如何使用 AnchoredDirectionArrows 類向 Matplotlib 繪圖新增視覺上吸引人的錨定方向箭頭。
import matplotlib.pyplot as plt import numpy as np import matplotlib.font_manager as fm from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDirectionArrows np.random.seed(19680801) fig, ax = plt.subplots(figsize=(7, 4)) ax.imshow(np.random.random((10, 10))) # Rotated arrow fontprops = fm.FontProperties(family='serif') rotated_arrow = AnchoredDirectionArrows( ax.transAxes, '30', '120', loc='center', color='w', angle=30, fontproperties=fontprops ) ax.add_artist(rotated_arrow) plt.show()
輸出
執行上述程式碼後,我們將獲得以下輸出 -
