如何在 Matplotlib 中僅繪製一張表格?
若要僅繪製一張表,我們可以採取以下步驟 -
- 使用子圖建立 fig 和 axs。建立一張圖形和一組子圖。
- 為 10 行和 3 列建立隨機資料。
- 為列名建立元組。
- axis('tight') - 設定僅足夠大到顯示所有資料的限制,然後停用進一步的自動縮放。
- axis('off') - 關閉座標軸線和標籤。與 ''False'' 相同。
- 要在座標軸上新增表格,請使用表格() 例項,其中包含列文字、列標籤、列和 location=center。
- 若要顯示圖形,請使用 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')
plt.show()輸出

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