開始使用免費開始

使用 matplotlib 座標軸

Seaborn 以 matplotlib 作為繪圖的底層函式庫。 多數情況下,你可以用 Seaborn 的 API 來調整視覺化; 但有時候,利用 matplotlib 的函式來客製化圖表也很實用。 在這種情況下,最重要的物件是 matplotlibaxes

一旦你取得一個 axes 物件,就能對圖表進行許多自訂設定。

在這些範例中,US HUD 的資料已載入到資料框 df,且所有函式庫都已匯入。

本練習屬於課程

Seaborn 資料視覺化中級

檢視課程

練習說明

  • 使用 plt.subplots() 建立 figure 與 axes 物件。
  • 在該座標軸上繪製欄位 fmr_3histplot
  • 將 x 軸標籤設為更有意義的「3 Bedroom Fair Market Rent」。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a figure and axes
fig, ax = plt.____()

# Plot the distribution of data
sns.histplot(df['fmr_3'], ax=ax)

# Create a more descriptive x axis label
ax.set(____="3 Bedroom Fair Market Rent")

# Show the plot
plt.show()
編輯並執行程式碼