Matplotlib Alt Noktaları
Çoklu Grafikleri Görüntüle
İşlev ile subplots()
tek bir şekilde birden fazla grafik çizebilirsiniz:
Örnek
2 arsa çizin:
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()
Sonuç:
subplots() Fonksiyonu
İşlev subplots()
, şeklin düzenini tanımlayan üç argüman alır.
Düzen, birinci ve ikinci argüman tarafından temsil edilen satırlar ve sütunlar halinde düzenlenir .
Üçüncü argüman, mevcut arsa indeksini temsil eder.
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.
Yani, 2 satır ve 1 sütunlu bir şekil istiyorsak (yani iki grafiğin yan yana yerine üst üste görüntüleneceği anlamına gelir), sözdizimini şöyle yazabiliriz:
Örnek
Üst üste 2 arsa çizin:
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()
Sonuç:
Tek bir şekil üzerine istediğiniz kadar grafik çizebilirsiniz, sadece satır, sütun ve grafiğin indeksini tanımlayın.
Örnek
6 arsa çizin:
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()
Sonuç:
Başlık
Şu fonksiyonla her arsaya bir başlık ekleyebilirsiniz title()
:
Örnek
2 arsa, başlıkları ile:
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()
Sonuç:
süper başlık
Şu fonksiyonla tüm şekle bir başlık ekleyebilirsiniz suptitle()
:
Örnek
Tüm şekil için bir başlık ekleyin:
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()
Sonuç: