如何在 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