【发布时间】:2019-03-29 16:43:13
【问题描述】:
我有一个 pandas 数据框,我使用 pandas.plot 函数绘制条形图。在函数中,我将表函数设置为 on。如何使用逗号分隔符格式化此随附表格中的值?
我可以对坐标轴值进行这些操作,而不是附表
我已经尝试将值转换为浮点数,但 pandas plot 只绘制整数,因此会给出错误消息“空数据框”:没有要绘制的数字数据。
ax1 = mydf.plot(kind='bar', title= chart with table, fontsize=8, width=0.75, legend=True, table=True)
ax1.legend(loc=5, bbox_to_anchor=(1.25,0.5), fontsize='x-small')
ax1.axes.get_xaxis().set_visible(False)
ax1.get_yaxis().get_major_formatter().set_scientific(False)
ax1.get_yaxis().set_major_formatter(ticker.StrMethodFormatter('${x:,.0f}'))
ax1.set_ylim(-10000000,10000000)
ax1.set_ylabel("P&L",fontsize=9)
ax1.axhline(0,0,1, color='k', linewidth=0.5)
table_ax1 = ax1.tables[0]
table_ax1.auto_set_font_size(False)
table_ax1.set_fontsize('8')
table_ax1.scale(1,2)
plt.tight_layout()
【问题讨论】:
标签: python pandas matplotlib matplotlib-table