如何利用 matplotlib.pyplot 更改表格的字號?
要使用 matplotlib 更改表格的字型大小,我們可以使用 set_fontsize() 方法。
步驟
- 建立一個圖形和一組子圖,nrows=1 和 ncols=1。
- 使用 numpy 建立隨機資料。
- 建立 columns 引數。
- 讓座標軸 tight 和 off。
- 初始化變數 fontsize 以更改字型大小。
- 使用 set_font_size() 方法設定表格的字型大小。
- 要顯示圖形,使用 show() 方法。
示例
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig, axs = plt.subplots(1, 1)
data = np.random.random((10, 3))
columns = ("Column I", "Column II", "Column III")
axs.axis('tight')
axs.axis('off')
the_table = axs.table(cellText=data, colLabels=columns, loc='center')
the_table.auto_set_font_size(False)
the_table.set_fontsize(10)
plt.show()輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP