ตกแต่งกราฟให้สมบูรณ์
เนื่องจาก plt.subplots() คืนค่าเป็น axes object จึงสามารถใช้เมธอด .set_title(), .set_xlabel() และ .set_ylabel() เพื่อเพิ่ม label ให้กับกราฟได้
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Python สำหรับผู้ใช้ R
คำแนะนำการฝึกหัด
- ใช้เมธอด
.set_title()บน axes เพื่อกำหนดชื่อกราฟ:'Histogram' - ใช้เมธอด
.set_xlabel()บน axes เพื่อกำหนดป้ายแกน:'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()