在 pandas .p​​lot() 函数中禁用科学记数法和偏移量

我有一个数据框 df,其中有 2 列我想一起绘制,天数作为索引:


           | 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 做到这一点?


catspeake
浏览 89回答 3
3回答

慕后森

您有几种选择:选项一:使用 Matplotlibaxes=fig.add_axes([0,0,1,1])axes.set_xticks() # with list or range() insideaxes.set_yticks() # with list or range() inside#You can also label the ticks with your desired valuesaxes.set_xticklabels() # with list or range() insideaxes.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我相信选项一更好,因为您只需要它用于图表并且不一定要修改您的数据框列。

慕哥6287543

您可以尝试更改axes.formatter.limits以下属性rcParams:plt.rcParams["axes.formatter.limits"] = (-5, 12)如果轴范围的 log10 小于第一个或大于第二个,则 Matplotlib 使用科学记数法。您可以自定义所需输出的下限和上限。

一只名叫tom的猫

用于.set_ylim([min,max])设置绘图的 y 轴限制
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python