使用 Seaborn FacetGrid(Matplotlib)繪製資料框中的誤差棒


若要使用 Seaborn FacetGrid 從資料框繪製誤差棒,我們可以按照以下步驟進行 -

  • 獲取一個二維、可調整大小、可能兼具異構內容的表格資料。
  • 用於繪製條件關係的多繪製格網。
  • 將繪製函式應用於資料中每個分面的子集。
  • 若要顯示圖形,請使用 **show()** 方法。

示例

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

df = pd.DataFrame({'col1': [3.0, 7.0, 8.0],
                  'col2': [1.0, 4.0, 3.0]})

g = sns.FacetGrid(df, col="col1", hue="col1")
g.map(plt.errorbar, "col1", "col2", yerr=0.75, fmt='o')

plt.show()

輸出

更新於: 18-6-2021

459 次瀏覽

點燃你的 職業

完成課程取得認證

開始
廣告