Issue
Given the following table:
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="")
I'd like to change the color of the numbers (1-5) to grey and the font size to 12 point.
Solution
You need to get text font properties of the cells:
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()
Another method to get text properties of the cell is used cell indexes (i, j):
table[(i, j)].get_text().set_fontsize(12)
table[(i, j)].get_text().set_color('red')
Matplotlib text font properties are described here: http://matplotlib.org/api/text_api.html#matplotlib.text.Text.set_fontproperties
As a result, the first code draw this figure:
Answered By - Serenity
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.