[英]Format a table that was added to a plot using pandas.DataFrame.plot
I'm producing a bar graph with a table using pandas.DataFrame.plot. 我正在使用pandas.DataFrame.plot生成带有表的条形图。
Is there a way to format the table size and/or font size in the table to make it more readable? 有没有一种方法可以格式化表格中的表格大小和/或字体大小,使其更具可读性?
My DataFrame (dfexe): 我的DataFrame(dfexe):
City State Waterfalls Lakes Rivers
LA CA 2 3 1
SF CA 4 9 0
Dallas TX 5 6 0
Create a bar chart with a table: 使用表格创建条形图:
myplot = dfex.plot(x=['City','State'],kind='bar',stacked='True',table=True)
myplot.axes.get_xaxis().set_visible(False)
Here is an answer. 这是一个答案。
# 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)
Note: Check also this answer for more information. 注意:也请查看此答案以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.