MatplotLib:一次格式化多个单元格
以下是我的matplotlib函数,用于按行或列格式化单元格:MatplotLib:一次格式化多个单元格,matplotlib,Matplotlib,以下是我的matplotlib函数,用于按行或列格式化单元格: def setRowWiseFont(table, rowIndices, fontWeight = None, fontColor = None, fontSize = None, fontAlignment = None): # Font Size Ranges 6 - 72 pts. Including medium as string #Alignments = 'center' | 'right' | 'left' if
def setRowWiseFont(table, rowIndices, fontWeight = None, fontColor = None, fontSize = None, fontAlignment = None):
# Font Size Ranges 6 - 72 pts. Including medium as string
#Alignments = 'center' | 'right' | 'left'
if fontAlignment == None:
fontAlignment = "center"
if fontColor == None:
fontColor = "black"
if fontSize == None:
fontSize = 6
if fontWeight == None:
fontWeight = "normal"
for (row, col), cell in table.get_celld().items():
if (row in rowIndices):
cell.set_text_props(fontproperties=FontProperties(weight=fontWeight, size = fontSize),ha = fontAlignment)
cell.get_text().set_color(fontColor)
return table
def setColumnWiseFont(表格,共索引,fontWeight=None,fontColor=None,fontSize=None,fontAlignment=None):
正如您所看到的,我能够使用上述两个函数格式化多个行和列,但从性能角度来看,此函数速度较慢。我感兴趣的东西,可以让我格式化多个单元格一次通过索引或什么。例如:
单元格[0:3,4:6]。格式()
有人知道怎么做吗
# Font Size Ranges 6 - 72 pts. Including medium as string
#Alignments = 'center' | 'right' | 'left'
if fontAlignment == None:
fontAlignment = "center"
if fontColor == None:
fontColor = "black"
if fontSize == None:
fontSize = 6
if fontWeight == None:
fontWeight = "normal"
for (row, col), cell in table.get_celld().items():
if (col in colIndices):
cell.set_text_props(fontproperties=FontProperties(weight=fontWeight, size = fontSize),ha = fontAlignment)
cell.get_text().set_color(fontColor)
plt.show()
return table