繁体   English   中英

在 pandas.plot() function 中禁用科学记数法和偏移

[英]Disable scientific notation and offset in pandas .plot() function

我有一个 dataframe df,有 2 列我想将 plot 和天作为索引:

           | col1  | col2   | col3 | ...
2020-01-01 | 1     | 300000 | ...
2020-01-02 | 1000  | 600000 | ...
2020-01-03 | 3000  | 50000  | ...

通过绘制 col1 + col2

df[["col1", "col2"]].plot()

显示从 0 到 1.0 和顶部“1e6”的值,如本例所示: https://i.stack.imgur.com/tJjgX.png

我想要 y 轴上的完整值范围并且没有科学记数法。 我怎样才能通过 pandas.plot() 或 matplotlib 做到这一点?

你有几个选择:

选项一:使用 Matplotlib

axes=fig.add_axes([0,0,1,1])
axes.set_xticks() # with list or range() inside
axes.set_yticks() # with list or range() inside

#You can also label the ticks with your desired values
axes.set_xticklabels() # with list or range() inside
axes.set_yticklabels() # with list or range() inside

选项二:更改 Pandas 设置

pd.set_option('display.float_format', lambda x: '%.3f' % x)

或者

pd.options.display.float_format = '{:.2f}'.format

我相信选项一更好,因为您只需要它用于图形并且不一定要修改您的 dataframe 列。

干杯!

您可以尝试更改rcParamsaxes.formatter.limits属性:

plt.rcParams["axes.formatter.limits"] = (-5, 12)

如果轴范围的 log10 小于第一个或大于第二个,Matplotlib 使用科学计数法。

使用.set_ylim([min,max])设置 plot 的 y 轴限制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM