माटप्लोटलिब सबप्लॉट्स
एकाधिक भूखंड प्रदर्शित करें
फ़ंक्शन के साथ subplots()
आप एक आकृति में कई प्लॉट बना सकते हैं:
उदाहरण
2 प्लॉट ड्रा करें:
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x =
np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(1, 2, 1)
plt.plot(x,y)
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30,
40])
plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.show()
परिणाम:
सबप्लॉट्स () फंक्शन
subplots()
फ़ंक्शन तीन तर्क लेता है जो आकृति के लेआउट का वर्णन करता है ।
लेआउट को पंक्तियों और स्तंभों में व्यवस्थित किया जाता है, जिन्हें पहले और दूसरे तर्क द्वारा दर्शाया जाता है।
तीसरा तर्क वर्तमान भूखंड के सूचकांक का प्रतिनिधित्व करता है।
plt.subplot(1, 2, 1)
#the figure has 1 row, 2 columns, and this plot is the first plot.
plt.subplot(1, 2, 2)
#the figure has 1 row, 2 columns, and this plot is the second plot.
इसलिए, यदि हम 2 पंक्तियों और 1 कॉलम के साथ एक आंकड़ा चाहते हैं (जिसका अर्थ है कि दो प्लॉट एक-दूसरे के ऊपर एक-दूसरे के ऊपर प्रदर्शित होंगे), तो हम सिंटैक्स को इस तरह लिख सकते हैं:
उदाहरण
एक दूसरे के ऊपर 2 प्लॉट बनाएं:
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x =
np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(2, 1, 1)
plt.plot(x,y)
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30,
40])
plt.subplot(2, 1, 2)
plt.plot(x,y)
plt.show()
परिणाम:
आप एक आकृति पर जितने चाहें उतने प्लॉट बना सकते हैं, बस पंक्तियों, स्तंभों की संख्या और प्लॉट की अनुक्रमणिका का वर्णन करें।
उदाहरण
6 प्लॉट ड्रा करें:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0,
1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(2, 3, 1)
plt.plot(x,y)
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30,
40])
plt.subplot(2, 3, 2)
plt.plot(x,y)
x = np.array([0, 1,
2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(2, 3, 3)
plt.plot(x,y)
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(2, 3, 4)
plt.plot(x,y)
x = np.array([0, 1, 2, 3])
y =
np.array([3, 8, 1, 10])
plt.subplot(2, 3, 5)
plt.plot(x,y)
x
= np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(2,
3, 6)
plt.plot(x,y)
plt.show()
परिणाम:
शीर्षक
title()
आप फ़ंक्शन के साथ प्रत्येक प्लॉट में एक शीर्षक जोड़ सकते हैं :
उदाहरण
2 भूखंड, शीर्षक के साथ:
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x =
np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(1, 2, 1)
plt.plot(x,y)
plt.title("SALES")
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30,
40])
plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.title("INCOME")
plt.show()
परिणाम:
सुपर शीर्षक
suptitle()
आप फ़ंक्शन के साथ संपूर्ण आकृति में एक शीर्षक जोड़ सकते हैं :
उदाहरण
संपूर्ण आकृति के लिए एक शीर्षक जोड़ें:
import matplotlib.pyplot as plt
import numpy as np
#plot 1:
x =
np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])
plt.subplot(1, 2, 1)
plt.plot(x,y)
plt.title("SALES")
#plot 2:
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30,
40])
plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.title("INCOME")
plt.suptitle("MY SHOP")
plt.show()
परिणाम: