
- 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 - 範圍滑塊
- 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 - 超連結
超連結,通常稱為連結,是一個導航元素,以各種形式呈現,例如文字、影像、圖示或按鈕,位於文件或網頁中。單擊或啟用時,超連結會將使用者重定向到指定的 URL 或資源,從而建立無縫且互動式的體驗。
Matplotlib 提供各種工具,用於在繪圖中包含超連結。在本教程中,您將瞭解如何在 Matplotlib 繪圖中新增超連結,例如 SVG 圖形和 PdfPages。
建立帶有超連結的 SVG 圖形
SVG(可縮放向量圖形)是一種基於 XML 的影像格式,支援超連結。但是,必須注意的是,Matplotlib 中的超連結專門適用於 SVG 輸出。如果繪圖儲存為靜態影像(例如 PNG 或 JPEG),或在視窗中顯示為繪圖,則超連結功能將無法使用。
在這種情況下,您可以在具有可點選元素的互動式繪圖中使用此功能。
示例
在此示例中,建立了一個散點圖,並使用 set_urls 方法為各個資料點分配超連結。
import matplotlib.pyplot as plt import numpy as np fig = plt.figure() s = plt.scatter([1, 2, 3], [4, 5, 6]) s.set_urls(['https://tutorialspoint.tw', 'https://tutorialspoint.tw/matplotlib/index.htm', None]) fig.savefig('scatter.svg')
輸出
執行上述程式碼後,您可以在輸出目錄中檢查 .svg 圖片檔案。

在 PdfPages 中新增超連結
matplotlib 中的PdfPages 模組允許建立多頁 PDF 文件。您可以使用 matplotlib 文字元素向這些 pdf 頁面新增超連結。
示例
在此示例中,使用 PdfPages 建立了一個 PDF 文件,並將帶有超連結的文字元素新增到繪圖中。
import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages msr_line4 = r'$\bf{' + 'Tutorialspoint\ Matplotlib\ Resource : ' + '}$' + "https://tutorialspoint.tw/matplotlib/index.htm" with PdfPages('Adding_hyperlink_inside_a_PdfPage.pdf') as pdf: plt.figure(figsize=(11, 8.5)) ax2 = plt.subplot2grid((9, 5), (1, 0), rowspan=1, colspan=2) ax2.text(0, 0, msr_line4, fontsize=9) plt.axis('off') pdf.savefig() plt.close
輸出
執行上述程式碼後,您可以在輸出目錄中檢查 .pdf 檔案。

互動式繪圖中的超連結
對於未渲染為 SVG 的繪圖(例如在 Matplotlib 視窗中顯示的互動式繪圖),可以使用事件處理程式實現超連結。透過建立一個函式來處理“pick”事件,您可以定義在單擊特定元素(如資料點)時要執行的操作。
示例
以下示例演示瞭如何在單擊資料點時在 Web 瀏覽器中開啟指定的超連結。
import matplotlib.pyplot as plt import webbrowser class CustomObject: def __init__(self, x, y, name): self.x = x self.y = y self.name = name def on_pick(event): webbrowser.open('https://tutorialspoint.tw') # Create custom objects obj_a = CustomObject(0.1, 0.3, "Object A") obj_b = CustomObject(0.2, 0.5, "Object B") # Plotting objects with picker attribute fig, ax = plt.subplots() for obj in [obj_a, obj_b]: artist = ax.plot(obj.x, obj.y, 'ro', picker=10)[0] artist.obj = obj # Connect pick event to the handler fig.canvas.callbacks.connect('pick_event', on_pick) plt.show()
輸出
觀看下面的影片瞭解輸出的樣子。

廣告