如何在 Seaborn/Matplotlib 中抑制因式圖 Y 軸中的科學記數法?


要在 Seaborn/Matplotlib 中抑制因式圖 Y 軸中的科學記數法,我們可以使用 ticklabel_format() 方法中的 style="plain"

步驟

  • 設定影像尺寸並調整子圖之間和周圍的填充。

  • 建立一個具有鍵 col1col2 的資料框。

  • factorplot() 已更名為 catplot()

  • 要抑制科學記數法,請使用 ticklabel_format() 方法中的 style="plain"

  • 要顯示圖形,請使用 show() 方法。

from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

df = pd.DataFrame({"col1": [1, 3, 5, 7, 1], "col2": [1, 5, 7, 9, 1]})

sns.catplot(y="col1", x="col2", kind='bar', data=df, label="Total", height=3.5)

plt.ticklabel_format(style='plain', axis='y')

plt.show()

輸出

更新於: 04-6 月-2021

5K+ 瀏覽量

開啟你的 職業生涯

完成課程並獲得認證

開始
廣告
© . All rights reserved.