開始使用免費開始

美化圖形

由於 plt.subplots() 會回傳一個 axes 物件,你可以使用 .set_title().set_xlabel().set_ylabel() 方法替圖形加上標籤。

本練習屬於課程

給 R 使用者的 Python

檢視課程

練習說明

  • 在座標軸上呼叫 .set_title() 方法,將圖的標題設為:'Histogram'。
  • 在座標軸上呼叫 .set_xlabel() 方法,將 x 軸標籤設為:'Total Bill'。

動手互動練習

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

import matplotlib.pyplot as plt
import seaborn as sns

# Create a figure with 1 axes
fig, ax = plt.subplots()

# Draw a histplot
ax = sns.histplot(tips['total_bill'], kde = True)

# Label the title and x axis
ax.____(____)
____
plt.show()
編輯並執行程式碼