Вот мой код.
Код: Выделить всё
# 1. Define the variable
import matplotlib.pyplot as plt
from matplotlib.table import Table
# Dummy data
data = [["Name", "Age", "Affiliation"],
["Bam", "12", "didoda"],
["Gireogi", "13", "Jadory"]]
# Define rows and columns
n_rows, n_cols = len(data), len(data[0])
width, height = 1.0 / n_cols, 1.0 / n_rows
# 2. Import Table and create figure
fig, ax = plt.subplots(figsize=(6, 3))
ax.axis('tight')
ax.axis('off')
table = Table(ax, bbox=[0, 0, 1, 1])
# 4. Add dummy data as cells
for i in range(n_rows):
for j in range(n_cols):
cell_text = data[i][j]
table.add_cell(i, j, width, height, text=cell_text, loc='center', edgecolor='black')
# 3. Refer to what I want to change (specific cell)
cell = table.get_celld()[(1, 2)] # Access cell at row 1, column 2
print(type(cell)) # Confirm the cell type
cell.set_fontsize(3.5) # Adjust font size for this specific cell
# Add the table to the axis
ax.add_table(table)
# Display the table
plt.show()
Определенно, я использую метод объекта Cell, который называется set_fontsize. я сохраняю размер всех ячеек в 20 пикселей, кроме ячейки в строке 1, столбце 2. Я хочу изменить ячейку в строке 1, столбце 2 (написано «дидода»), как 3.5. Почему он меняет всю ячейку таблицы?
введите здесь описание изображения
Результат в этом коде отображается поверх изображения.
Подробнее здесь: https://stackoverflow.com/questions/792 ... matplotlib
Мобильная версия