我有一個數據框 df,其中有 2 列我想一起繪制,天數作為索引: | col1 | col2 | col3 | ...2020-01-01 | 1 | 300000 | ...2020-01-02 | 1000 | 600000 | ...2020-01-03 | 3000 | 50000 | ...通過繪制 col1 + col2df[["col1", "col2"]].plot()顯示從 0 到 1.0 和頂部“1e6”的值,如本示例所示: https: //i.stack.imgur.com/tJjgX.png我想要 y 軸上的完整值范圍,沒有科學記數法。我怎樣才能通過 pandas .plot() 或 matplotlib 做到這一點?
3 回答

慕后森
TA貢獻1802條經驗 獲得超5個贊
您有幾種選擇:
選項一:使用 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
我相信選項一更好,因為您只需要它用于圖表并且不一定要修改您的數據框列。

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
您可以嘗試更改axes.formatter.limits
以下屬性rcParams
:
plt.rcParams["axes.formatter.limits"] = (-5, 12)
如果軸范圍的 log10 小于第一個或大于第二個,則 Matplotlib 使用科學記數法。
您可以自定義所需輸出的下限和上限。
添加回答
舉報
0/150
提交
取消