Python Matplotlib表格行标签字体颜色和大小

Python Matplotlib表格行标签字体颜色和大小,python,python-3.x,matplotlib,Python,Python 3.x,Matplotlib,鉴于下表: 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,wi

鉴于下表:

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="")


我想把数字(1-5)的颜色改成灰色,字体大小改成12点

您需要获取单元格的文本字体属性:

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):

Matplotlib文本字体属性如下所述:

因此,第一个代码绘制了此图:

谢谢你,斯坦利。如果我的表是一个轴(即ax1.table(cellText…)?当我这样尝试并使用ax1.properties()而不是table.properties()时,我得到了“KeyError:'child_Artisters'”。不是每个
matpoltlib
对象都有一个§child_Artisters§方法。@DanceParty2:应该仍然有效。换句话说,
table=ax[1]。table(cellText…)
然后
table.properties()
。我不能保证这适用于每个版本的Matplotlib,但它适用于v1.3.1。我在“children”下找到了子单元格,而不是“child\u”
table[(i, j)].get_text().set_fontsize(12)
table[(i, j)].get_text().set_color('red')