|
>>> plt.show()
Ekraningizda shunga o‘xshash narsani ko‘rishingiz kerak
|
bet | 128/182 | Sana | 19.05.2024 | Hajmi | 5,69 Mb. | | #244351 |
Bog'liq Python sun\'iy intellekt texnologiyasi Dasrlik 2024>>> plt.show()
Ekraningizda shunga o‘xshash narsani ko‘rishingiz kerak:
10.1.1-rasm.Dastur natija oynasi
Batafsil DataFrame manipulyatsiyasi va chizmalari
DataFrame va numpy bizga ma’lumotlarni manipulyatsiya qilishning boshqa usullarini beradi. Masalan, biz qoidabuzarlarning yosh gistogrammasini quyidagicha tuzishimiz mumkin:
>>> ages = data['Cited Person Age’].astype(int)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
>>> plt.show()
10.1.2 a-rasm. Yosh gistogrammasi
Bu ehtimol ma’lumotlardagi xatodir, shuning uchun biz ushbu ma’lumotlar nuqtalarini osongina olib tashlashimiz va gistogrammani qayta tuzishimiz mumkin:
>>> ages = ages[ages < 100]
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
>>> plt.show()
10.1.2 b-rasm. Yosh gistogrammasi
Plotlarni PDF formatida saqlash
Ko‘pincha siz matplotlib grafigini shunchaki ekranda ko‘rish o‘rniga PDF yoki SVG fayl sifatida saqlashni xohlaysiz. Ikkalasi uchun biz rasm yaratishimiz va gistogrammani avvalgidek chizishimiz kerak:
>>> fig = plt.figure()
>>> ax = fig.add_subplot(1, 1, 1)
>>> plt.hist(ages, bins=np.max(ages) - np.min(ages))
Ushbu plt.show()-ni chaqirish o‘rniga SVG sifatida saqlash uchun plt.savefig() ni chaqirishimiz mumkin:
>>> plt.savefig('hist.svg’)
Agar biz rasmni PDF sifatida saqlamoqchi bo‘lsak, PdfPages modulidan savefig() bilan birga foydalanishimiz kerak:
>>> import matplotlib.patches as mpatches
>>> from matplotlib.backends.backend_pdf import PdfPages
|
| |