plt.subplots के साथ small multiples बनाना
Small multiples का उपयोग कई datasets को साथ-साथ प्लॉट करने के लिए किया जाता है। Matplotlib में, small multiples को plt.subplots() फंक्शन से बनाया जा सकता है। पहला आर्ग्युमेंट Axes ऑब्जेक्ट्स की array में पंक्तियों (rows) की संख्या है और दूसरा आर्ग्युमेंट कॉलम्स की संख्या। इस अभ्यास में, आप Austin और Seattle के डेटा का उपयोग करके subplots की एक array बनाना और उसे भरना अभ्यास करेंगे।
डेटा आपको DataFrames के रूप में दिया गया है: seattle_weather और austin_weather। इन दोनों में "MONTH" कॉलम है और "MLY-PRCP-NORMAL" (औसत वर्षा/precipitation के लिए), साथ ही "MLY-TAVG-NORMAL" (औसत तापमान के लिए) कॉलम्स हैं। इस अभ्यास में, आप प्रत्येक शहर के मासिक औसत वर्षा और औसत तापमान को अलग-अलग subplot में प्लॉट करेंगे।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Matplotlib के साथ डेटा विज़ुअलाइज़ेशन परिचय
अभ्यास निर्देश
- 2 rows और 2 columns के साथ एक Figure और subplots की array बनाइए.
- ऊपर-बाएँ Axes को इंडेक्स 0, 0 मानते हुए, Seattle की precipitation प्लॉट कीजिए.
- ऊपर-दाएँ (इंडेक्स 0, 1) में Seattle के temperatures प्लॉट कीजिए.
- नीचे-बाएँ (1, 0) और नीचे-दाएँ (1, 1) में Austin की precipitation और temperatures प्लॉट कीजिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Create a Figure and an array of subplots with 2 rows and 2 columns
fig, ax = plt.subplots(____, ____)
# Addressing the top left Axes as index 0, 0, plot month and Seattle precipitation
ax[0, 0].plot(____, ____)
# In the top right (index 0,1), plot month and Seattle temperatures
ax[0, 1].plot(____, ____)
# In the bottom left (1, 0) plot month and Austin precipitations
ax[____].plot(____, ____)
# In the bottom right (1, 1) plot month and Austin temperatures
ax[____].plot(____, ____)
plt.show()