[英]Matplotlib Table Row Label Font Color and Size
您需要獲取單元格的文本字體屬性:
import matplotlib.pyplot as plt
table=plt.table(cellText=[' ', ' ', ' ', ' ', ' '], #rows of data values
rowLabels=['1','2','3','4','5'],
cellLoc="left",
rowLoc='left',
bbox=[0,0,.2,1],#[left,bottom,width,height]
edges="")
# iterate through cells of a table
table_props = table.properties()
table_cells = table_props['child_artists']
for cell in table_cells:
cell.get_text().set_fontsize(20)
cell.get_text().set_color('grey')
plt.show()
另一種獲取單元格文本屬性的方法是使用單元格索引 (i, j):
table[(i, j)].get_text().set_fontsize(12)
table[(i, j)].get_text().set_color('red')
Matplotlib 文本字體屬性在此處描述: http ://matplotlib.org/api/text_api.html#matplotlib.text.Text.set_fontproperties
受問題評論的啟發,我將代碼修改為table_cells = table.properties().get('child_artists') or table.properties()['children']
並且它起作用了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.