使用pandas.DataFrame.plot格式化添加到绘图中的表 [英] Format a table that was added to a plot using pandas.DataFrame.plot
本文介绍了使用pandas.DataFrame.plot格式化添加到绘图中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用pandas.DataFrame.plot生成带有表的条形图.
I'm producing a bar graph with a table using pandas.DataFrame.plot.
是否可以格式化表格中的表格大小和/或字体大小以使其更具可读性?
Is there a way to format the table size and/or font size in the table to make it more readable?
我的DataFrame(dfexe):
My DataFrame (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)
输出:
推荐答案
以下是答案.
# 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.
这篇关于使用pandas.DataFrame.plot格式化添加到绘图中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文