การเพิ่ม annotation
การปรับแต่งแต่ละอย่างที่ได้เรียนมาสามารถนำมาใช้ร่วมกันได้ ในแบบฝึกหัดนี้ เราจะเพิ่ม annotation ลงในกราฟการกระจายข้อมูล เพื่อแสดงเส้นบอกค่าเฉลี่ยและค่ามัธยฐานของราคาค่าเช่า
สำหรับตัวอย่างนี้ ได้เปลี่ยน palette เป็น bright แล้ว
โดยใช้ sns.set_palette()
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้างภาพข้อมูลระดับกลางด้วย Seaborn
คำแนะนำการฝึกหัด
- สร้าง figure และ axes
- พล็อตการกระจายของคอลัมน์
fmr_1 - เพิ่มเส้นแนวตั้งโดยใช้
axvlineสำหรับค่าmedianและmeanที่กำหนดไว้แล้ว
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create a figure and axes. Then plot the data
fig, ax = plt.subplots()
sns.histplot(df['fmr_1'], ax=ax)
# Customize the labels and limits
ax.set(____="1 Bedroom Fair Market Rent", xlim=(100,1500), title="US Rent")
# Add vertical lines for the median and mean
ax.axvline(x=____, color='m', label='Median', linestyle='--', linewidth=2)
ax.axvline(x=____, color='b', label='Mean', linestyle='-', linewidth=2)
# Show the legend and plot the data
ax.____()
plt.show()