在matplotlib图的y轴上更改数字格式

问题描述

我已经在matplotlib中制作了条形图。在该图表中,我设法更改了y轴上数字的格式。唯一的问题是千位分隔符现在是逗号(',')。由于我住在荷兰,所以我非常想将其转换为点('。')。看起来很简单,但是我找不到任何方法。请参见下面的代码

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline

top = [72000,73000,78000,71000]
base = [15000,12000,13000,14000]

x = ['2017','2018','2019','2020']
x_ax = pd.Series(x)

fig,ax = plt.subplots()
ax.bar(x,top,label='TOP CUSTOMERS')
ax.bar(x,base,bottom=top,label='BASE CUSTOMERS')
ax.set_title('TON YTD JULY')
ax.legend(loc='lower center')
ax.set_ylabel('Ton')
ax.yaxis.set_major_formatter(mpl.ticker.StrMethodFormatter('{x:,.0f}'))
plt.savefig('C:/Users/MBRU/Box Sync/Data_Source/out/320/example.png',bBox_inches='tight')
plt.show()

Example of graph with code

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)