avi*_*iss 2 matplotlib python-2.7 pandas
这是我要绘制的数据框:
my_dic = {'stats': {'apr': 23083904,
'may': 16786816,
'june': 26197936,
}}
my_df = pd.DataFrame(my_dic)
my_df.head()
Run Code Online (Sandbox Code Playgroud)
这是我的绘图方式:
ax = my_df['stats'].plot(kind='bar', legend=False)
ax.set_xlabel("Month", fontsize=12)
ax.set_ylabel("Stats", fontsize=12)
ax.ticklabel_format(useOffset=False) #AttributeError: This method only works with the ScalarFormatter.
plt.show()
Run Code Online (Sandbox Code Playgroud)
剧情:
我想控制科学计数法。如其他问题所建议,我试图通过此行抑制它,plt.ticklabel_format(useOffset=False)但出现此错误- AttributeError: This method only works with the ScalarFormatter。理想情况下,我想以(mln)显示数据。
avi*_*iss 11
添加此行有助于以简单格式获取数字,但使用 ',' 看起来更好:
ax.get_yaxis().set_major_formatter(
matplotlib.ticker.FuncFormatter(lambda x, p: format(int(x), ',')))
Run Code Online (Sandbox Code Playgroud)
然后我可以根据int(x)/需要转换为百万或千:
由于您已经在使用 pandas
import matplotlib.pyplot as plt
my_df.plot(kind='bar')
plt.ticklabel_format(style='plain', axis='y')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4127 次 |
| 最近记录: |