एक ही आकृति पर एकाधिक मैटप्लोटलिब प्लॉट कैसे बनाएं


आप एक ही आकृति में एकाधिक Matplotlib प्लॉट बनाने के लिए निम्नलिखित सिंटैक्स का उपयोग कर सकते हैं:

 import matplotlib. pyplot as plt

#define grid of plots
fig, axs = plt. subplots (nrows= 2 , ncols= 1 )

#add data to plots
axs[0]. plot (variable1, variable2)
axs[1]. plot (variable3, variable4)

निम्नलिखित उदाहरण दिखाते हैं कि व्यवहार में इस फ़ंक्शन का उपयोग कैसे करें।

उदाहरण 1: पथों को लंबवत रूप से व्यवस्थित करना

निम्नलिखित कोड दिखाता है कि लंबवत रूप से व्यवस्थित तीन मैटप्लोटलिब प्लॉट कैसे बनाएं:

 #create some data
var1 = [1, 2, 3, 4, 5, 6]
var2 = [7, 13, 16, 18, 25, 19]
var3 = [29, 25, 20, 25, 20, 18]

#define grid of plots
fig, axs = plt. subplots (nrows= 3 , ncols= 1 )

#add title
fig. suptitle (' Plots Stacked Vertically ')

#add data to plots
axs[0]. plot (var1, var2)
axs[1]. plot (var1, var3)
axs[2]. plot (var2, var3)

Matplotlib में एकाधिक प्लॉट लंबवत रूप से स्टैक्ड हैं

उदाहरण 2: पथों को क्षैतिज रूप से व्यवस्थित करना

निम्नलिखित कोड दिखाता है कि क्षैतिज रूप से व्यवस्थित तीन मैटप्लोटलिब प्लॉट कैसे बनाएं:

 #create some data
var1 = [1, 2, 3, 4, 5, 6]
var2 = [7, 13, 16, 18, 25, 19]
var3 = [29, 25, 20, 25, 20, 18]

#define grid of plots
fig, axs = plt. subplots (nrows= 1 , ncols= 3 )

#add title
fig. suptitle (' Plots Stacked Horizontally ')

#add data to plots
axs[0]. plot (var1, var2)
axs[1]. plot (var1, var3)
axs[2]. plot (var2, var3) 

एकाधिक Matplotlib प्लॉट क्षैतिज रूप से स्टैक्ड हैं

उदाहरण 3: एक प्लॉट ग्रिड बनाएं

निम्नलिखित कोड दिखाता है कि Matplotlib प्लॉट ग्रिड कैसे बनाया जाए:

 #create some data
var1 = [1, 2, 3, 4, 5, 6]
var2 = [7, 13, 16, 18, 25, 19]
var3 = [29, 25, 20, 25, 20, 18]
var4 = [4, 4, 6, 4, 7, 11]

#define grid of plots
fig, axs = plt. subplots (nrows= 2 , ncols= 2 )

#add title
fig. suptitle (' Grid of Plots ')

#add data to plots
axs[0, 0]. plot (var1, var2)
axs[0, 1]. plot (var1, var3)
axs[1, 0]. plot (var1, var4)
axs[1, 1]. plot (var3, var1)

Matplotlib में एकाधिक प्लॉट

उदाहरण 4: पार्सल के बीच अक्ष साझा करें

आप यह सुनिश्चित करने के लिए शेयरएक्स और शेयरी तर्कों का उपयोग कर सकते हैं कि एकाधिक प्लॉट एक ही एक्स-अक्ष का उपयोग करते हैं:

 #create some data
var1 = [1, 2, 3, 4, 5, 6]
var2 = [7, 13, 16, 18, 25, 19]
var3 = [29, 25, 20, 25, 20, 18]
var4 = [4, 4, 6, 4, 7, 11]

#define grid of plots
fig, axs = plt. subplots (nrows= 2 , ncols= 2 , sharex= True , sharey= True )

#add title
fig. suptitle (' Grid of Plots with Same Axes ')

#add data to plots
axs[0, 0]. plot (var1, var2)
axs[0, 1]. plot (var1, var3)
axs[1, 0]. plot (var1, var4)
axs[1, 1]. plot (var3, var1) 

साझा अक्षों के साथ मैटप्लोटलिब में एकाधिक प्लॉट

अतिरिक्त संसाधन

मैटप्लोटलिब सबप्लॉट्स के बीच रिक्ति को कैसे समायोजित करें
Matplotlib में बैकग्राउंड का रंग कैसे बदलें
Matplotlib में प्लॉट का आकार कैसे बढ़ाएं

एक टिप्पणी जोड़ने

आपका ईमेल पता प्रकाशित नहीं किया जाएगा. आवश्यक फ़ील्ड चिह्नित हैं *