
- 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 - Quiver 圖
- Matplotlib 有用資源
- Matplotlib - 快速指南
- Matplotlib - 有用資源
- Matplotlib - 討論
Matplotlib - 字型索引
在 Matplotlib 庫中,字型索引指的是訪問和利用可用於渲染繪圖中文字元素的不同字型或字型的過程。Matplotlib 庫提供了對各種字型的訪問,瞭解字型索引涉及瞭解如何透過其名稱或索引使用這些字型。當我們想要使用不在預設集合中的字型或需要使用系統特定的字型時,這一點尤其重要。
Matplotlib 中的 font.family 引數接受表示已知字體系列的字串或表示特定字型索引的整數。數字索引用於引用在 Matplotlib 庫中註冊的字型。
Matplotlib 中的字型索引
以下是 matplotlib 庫中的字型索引方法。
字體系列
Matplotlib 庫提供了幾個字體系列,例如 'serif'、'sans-serif'、'monospace' 等。
這些字體系列具有其獨特的特徵,用於定義字型的總體設計。
字型名稱
Matplotlib 庫允許使用特定的字型名稱來訪問系統上可用的特定字型。
字型名稱能夠選擇自定義或已安裝的字型來渲染繪圖中的文字。
按名稱訪問字型
要訪問 Matplotlib 中的字型,我們可以使用字型名稱及其索引(如果可用)。
字型名稱
我們可以使用字型名稱訪問 matplotlib 中可用的字型。以下是使用 plt.rcParams['font.family'] 方法訪問 'Times New Roman' 字型的示例。
示例
import matplotlib.pyplot as plt plt.rcParams['font.family'] = 'Times New Roman' # Creating a data x = [i for i in range(10,40)] y = [i for i in range(30,60)] # Creating a plot plt.scatter(x,y,color = 'blue') plt.xlabel('X-axis cube values') plt.ylabel('Y-axis cube values') plt.title('Title with Times New Roman Font') plt.show()
輸出

系統上的可用字型
Matplotlib 庫還可以使用系統上的可用字型。可用的字型可能因作業系統(如 Windows、macOS、Linux)以及已安裝的字型庫而異。
使用 findSystemFonts() 索引字型
Matplotlib 提供了一個名為 matplotlib.font_manager.findSystemFonts() 的函式,該函式返回系統上可用字型的路徑列表。
示例
在此示例中,我們使用 matplotlib.font_manager.findSystemFonts() 函式獲取所需的字型名稱索引列表。
import matplotlib.font_manager as fm # Get a list of available fonts font_list = fm.findSystemFonts() # Display the first five fonts path print("The first five fonts path:",font_list[:5])
輸出
The first five fonts path: ['C:\\Windows\\Fonts\\gadugi.ttf', 'C:\\WINDOWS\\Fonts\\COPRGTB.TTF', 'C:\\WINDOWS\\Fonts\\KUNSTLER.TTF', 'C:\\Windows\\Fonts\\OLDENGL.TTF', 'C:\\Windows\\Fonts\\taileb.ttf']
按索引訪問字型
字型索引涉及瞭解系統上可用字型的名稱或路徑。我們可以透過其名稱、別名或檔案路徑來引用這些字型,以在 Matplotlib 繪圖中設定字體系列,確保將所需的字型用於文字元素。
示例
在此示例中,我們使用字型路徑從系統訪問字型。
import matplotlib as mpl import matplotlib.font_manager as fm plt.rcParams['font.family'] = 'C:\Windows\Fonts\Comicz.ttf' # Creating a data x = [i for i in range(10,40)] y = [i for i in range(30,60)] # Creating a plot plt.plot(x,y,color = 'violet') plt.xlabel('X-axis cube values') plt.ylabel('Y-axis cube values') plt.title("The plot fonts with font indexing") plt.show()
輸出

注意
字型索引和可用性可能會因 Matplotlib 庫中使用的後端而異。
使用索引自定義字型可能是特定於後端的,或者需要特殊的配置,例如 LaTeX 渲染。