Small multiples ที่แชร์แกน y
การสร้าง small multiples มักต้องการให้กราฟแต่ละอันแสดงผลด้วยสเกลเดียวกันบนแกน y ซึ่งทำได้โดยตั้งค่าคีย์เวิร์ด sharey เป็น True
ในแบบฝึกหัดนี้ จะได้สร้าง Figure ที่มี Axes สองอันซึ่งแชร์แกน y ร่วมกัน โดยข้อมูลจะอยู่ใน DataFrame seattle_weather และ austin_weather เช่นเดิม
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้างภาพข้อมูลด้วย Matplotlib เบื้องต้น
คำแนะนำการฝึกหัด
- สร้าง Figure ที่มีอาร์เรย์ของ Axes สองอันซึ่งแชร์ช่วงแกน y ร่วมกัน
- พล็อต
"MLY-PRCP-NORMAL"ของซีแอตเทิลเป็นเส้นทึบสีน้ำเงินใน Axes บน - เพิ่ม
"MLY-PRCP-25PCTL"และ"MLY-PRCP-75PCTL"ของซีแอตเทิลเป็นเส้นประสีน้ำเงินใน Axes บน - พล็อต
"MLY-PRCP-NORMAL"ของออสตินเป็นเส้นทึบสีแดงใน Axes ล่าง และพล็อต"MLY-PRCP-25PCTL"กับ"MLY-PRCP-75PCTL"เป็นเส้นประสีแดง
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create a figure and an array of axes: 2 rows, 1 column with shared y axis
fig, ax = plt.subplots(2, 1, sharey=True)
# Plot Seattle precipitation data in the top axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)
# Plot Austin precipitation data in the bottom axes
____.plot(____, ____, color = ____)
____.plot(____, ____, color = ____, linestyle = ____)
____.plot(____, ____, color = ____, linestyle = ____)
plt.show()