
- 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 - 數學表示式
一般來說,數學表示式是在給定的數學環境中遵循特定規則的符號組合。這些符號可以表示數字、變數、運算、函式等等。數學表示式的結構遵循確定運算順序和其他邏輯語法方面的規則。
以下是一些數學表示式的例子:

Matplotlib中的數學表示式
Matplotlib允許使用者在文字元素(文字物件)中包含數學表示式,以增強繪圖和圖形中數學元素的視覺化表示。
下圖顯示了在matplotlib繪圖中包含數學表示式:

Matplotlib中的Mathtext
Matplotlib使用名為Mathtext的模組來渲染繪圖中的數學表示式。它是一個輕量級的TeX表示式解析器和佈局引擎,用於在Matplotlib中渲染數學表示式。
Mathtext的關鍵特性
Mathtext支援各種特性,例如:
符號
特殊字元
下標、上標和標準函式名
分數和二項式
根式
不同的字型等等
Mathtext表示式應括在美元符號('$')中,可以包含各種符號和命令。文字物件(如標題、標籤、註釋和圖形文字)是Matplotlib中包含數學表示式的常見位置。
基本的數學文字
基本的數學文字可以包含像‘+’、‘-’、‘*’……這樣的二元運算子,來表示兩個元素之間的各種數學運算。
示例
此示例演示了包含像+,−這樣的二元運算子,分別表示加法和減法。
import matplotlib.pyplot as plt # Create a plot fig = plt.figure(figsize=(7, 4)) # Displaying basic mathematical text plt.text(.5, .5, r"$x^2 - 4x + 7$", fontsize=16, ha='center') # Show the plot plt.show()
輸出
執行上述程式碼後,我們將得到以下輸出:

根式、希臘字母和定界符
根式、希臘字母和定界符是數學表示式中的關鍵組成部分。
根式用平方根符號(√)表示,表示一個數字或表示式的根。
希臘字母,例如α(alpha)、β(beta)、γ(gamma)等等,是用於表示標準數學符號的符號。
定界符,包括括號、方括號和花括號,用於對錶達式進行分組,同時保持數學語句中正確的運算順序。
示例
這是一個包含帶根式、希臘字母和定界符的數學表示式的例子。
import matplotlib.pyplot as plt # Create a figure fig = plt.figure(figsize=(7, 4)) # Add Greek Letters within the plots plt.text(0.25, 0.2, r'Greek Letters: $\alpha, \beta, \gamma$', fontsize=16) # Radicals plt.text(0.3, 0.5, r'Radical: $\sqrt{2}$', fontsize=16) # delimiters plt.text(0.2, 0.8, r'delimiters: $(a + b) \left\{c - d\right\}$', fontsize=16) # Show the plot plt.show()
輸出
執行上述程式碼後,我們將得到以下輸出:

分數、二項式和疊加數字
分數是兩個數字的比率,寫成一個數字在另一個數字之上,表示一個量除以另一個量。
二項式包含兩項的表示式,通常用加法或減法連線。在二項式係數的上下文中,二項式可以表示集合中的組合或選擇。
疊加數字是指數值的垂直對齊,通常出現在數學符號中,例如指數或巢狀表示式。
示例
這是一個包含帶分數、二項式和疊加數字的數學表示式的例子。
import matplotlib.pyplot as plt # Create a plot fig = plt.figure(figsize=(7, 4)) # Fractions, binomials, and stacked numbers plt.text(0.4, 0.7, r'$\frac{3}{4} \binom{3}{4} \genfrac{}{}{0}{}{3}{4}$', fontsize=16) plt.text(0.4, 0.3, r'$\left(\frac{5 - \frac{1}{x}}{4}\right)$', fontsize=16) plt.show()
輸出
上述示例產生以下輸出:

下標、上標和標準函式名
在數學符號中,下標和上標分別用於表示索引或指數。而標準函式名是常用的數學函式,例如正弦、餘弦、對數和求和,通常用特定的符號或縮寫表示。
示例
這是一個包含帶下標、上標和標準函式名的數學表示式的例子。
import matplotlib.pyplot as plt # Create a figure fig = plt.figure(figsize=(7, 4)) # Add mathmetical expression with Subscripts, Superscripts and Standard Function Names plt.text(0.3, 0.6, r'$\sum_{i=0}^\infty x_i \quad \sin(\theta) \quad \log(e^x)$', fontsize=16) # Subscripts and superscripts plt.text(0.5, 0.3, r'$\log^a_i (x)$', fontsize=16) # Show the plot plt.show()
輸出
以下是上述示例的輸出:

示例
這是另一個在座標軸標籤和圖例中編寫下標文字的示例。
import numpy as np import matplotlib.pyplot as plt # Adjust figure size and autolayout plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Generate data x = np.linspace(1, 10, 1000) y = np.exp(x) # Plot data plt.plot(x, y, label=r'$e^x$', color="red", linewidth=2) # Set axis labels plt.xlabel("$X_{\mathrm{axis}}$") plt.ylabel("$Y_{\mathrm{axis}}$") # Set legend plt.legend(loc='upper left') # Display plot plt.show()
輸出
執行上述程式碼後,您將得到以下輸出:
