2016-09-23 78 views
0

我正在使用pandas.DataFrame.plot生成帶有表格的條形圖。使用pandas.DataFrame.plot格式化已添加到繪圖的表格

有沒有一種方法來格式化表中的表大小和/或字體大小,使其更具可讀性?

我的數據框(dfexe):

City State Waterfalls Lakes Rivers 
LA CA 2 3 1 
SF CA 4 9 0 
Dallas TX 5 6 0 

與表創建條形圖:

myplot = dfex.plot(x=['City','State'],kind='bar',stacked='True',table=True) 
myplot.axes.get_xaxis().set_visible(False) 

輸出: enter image description here

回答

2

這裏有一個答案。

# Test data 
dfex = DataFrame({'City': ['LA', 'SF', 'Dallas'], 
'Lakes': [3, 9, 6], 
'Rivers': [1, 0, 0], 
'State': ['CA', 'CA', 'TX'], 
'Waterfalls': [2, 4, 5]}) 

myplot = dfex.plot(x=['City','State'],kind='bar',stacked='True',table=True) 
myplot.axes.get_xaxis().set_visible(False) 
# Getting the table created by pandas and matplotlib 
table = myplot.tables[0] 
# Setting the font size 
table.set_fontsize(12) 
# Rescaling the rows to be more readable 
table.scale(1,2) 

enter image description here

注:檢查也this答案以獲取更多信息。

+0

X,非常感謝。我也注意到這個方法需要設置,才能真正增加字體大小:table.auto_set_font_size(False) – sparrow

+0

噢好吧,但我的版本並非如此(可能它與matplotlib和/或pandas版本),字體可以增加而不用調用這個函數。 – Romain

+0

後續問題:)。你知道如何在底部以外的其他地方打印表格嗎? – sparrow