Dùng set_fontsize() trên đối tượng table trả về bởi axs.table().
- Tạo figure, axs = subplots(1,1).
- Tạo dữ liệu ngẫu nhiên 10x3, columns labels.
- 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).
- show().
Ví dụ
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()
Kết quả
Bảng 10x3 hiển thị ở giữa figure với font size 10.