python - advanced - 18 - Matplotlib
Matplotlib
bilgileri grafik uzerine gostermek icin kullanilir
pip install matplotlib
import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3,4]
y=[1,4,9,16]
plt.plot(x,y,"o-r")
plt.axis([0,6,0,20])
plt.title("yokomako")
plt.xlabel("totmoto")
plt.ylabel("shoshondama")
plt.show()
#
grafik ekrana cikar
ayrica grafikte yapilabilecek diger islemler
import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3,4]
y=[1,4,9,16]
plt.plot(x,y,color="red",linewidth="3") # cizgi renk ve kalinligi degistirmek
plt.show()
yesil aralikli cizgi plot
plt.plot(x,y,'--g')
kesisme nokta yuvarlak olsun + yesil aralikli cizgi
plt.plot(x,y,'o--g')
legend
plt.plot(x,y,'o--g',label="something")
plt.legend()
uc adet grafik alt alta sergilensin
x=np.linspace(0,2,100)
fig,axs = plt.subplots (3) #3 adet grafik
axs[0].plot(x,x,color="red")
axs[0].set_title("linear")
axs[1].plot(x,x**2,color="purple")
axs[1].set_title("quadratic")
axs[2].plot(x,x**2,color="yellow")
axs[2].set_title("cubic")
plt.tight_layout() # grafik ciktida grafikler arasi bosluk birakir
plt.show()
baska gorunumle sunum:
x=np.linspace(0,2,100)
fig,axs = plt.subplots (2,2) #4 adet grafik
axs[0,0].plot(x,x,color="red")
axs[0,0].set_title("linear")
axs[0,1].plot(x,x**2,color="purple")
axs[0,1].set_title("quadratic")
axs[1,0].plot(x,x**3,color="yellow")
axs[1,0].set_title("cubic")
axs[1,1].plot(x,x**4,color="green")
axs[1,1].set_title("**4")
plt.tight_layout()
plt.show()
Ekranda belirli konuma koyarak + grafigin buyuklugunu soyleyerek graifigi yazdirmak
axes = figure.add_axes([0.2,0.1,0.7,0.8])
turuncu olan degerler soldan ve asagidan itibaren yeri yuze olarak belirler: %20 sagdan itibaren yer al
mavi deger ise grafik buyuklugunu belirtir: %70 en, %80 yukseklik
Bunu kullanarak iki grafigi ust uste yazdirmak da mumkun
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(10,90,20)
y = x**3
figure = plt.figure()
axes = figure.add_axes([0.2,0.1,0.7,0.8])
#kagitta soldan ve asagidan ne kadar uzak 0.2,0.1 - y label icin gerekli
#kagitta grafik ne kadar yer kaplayacak 0.7,0.8
# kalan 0.1 bosluk kagidin sagina ve uste yapismasin diye bosluk
axes.plot(x,y,"b") # blue color
axes.set_xlabel("XX label")
axes.set_ylabel("YY label")
axes.set_title("Cube")
plt.tight_layout()
plt.show()
Comments
Post a Comment