Python- tutoriaal

Python TUIS Python Intro Python Begin Python-sintaksis Python-kommentaar Python veranderlikes Python-datatipes Python-nommers Python Casting Python Strings Python Booleans Python-operateurs Python-lyste Python Tuples Python-stelle Python Woordeboeke Python As...Anders Python While Loops Python vir lusse Python-funksies Python Lambda Python-skikkings Python-klasse/-voorwerpe Python Erfenis Python Iterators Python-omvang Python-modules Python-datums Python Wiskunde Python JSON Python RegEx Python PIP Python Probeer ... Behalwe Python-gebruikersinvoer Python String Formatering

Lêerhantering

Python-lêerhantering Python Lees lêers Python Skryf/skep lêers Python verwyder lêers

Python-modules

NumPy Tutoriaal Panda Walkthrough Scipy Tutoriaal

Python Matplotlib

Matplotlib Intro Matplotlib Begin Matplotlib Pyplot Matplotlib Plotte Matplotlib Merkers Matplotlib-lyn Matplotlib-etikette Matplotlib-rooster Matplotlib Subplotte Matplotlib Scatter Matplotlib Bars Matplotlib Histogramme Matplotlib sirkeldiagramme

Masjienleer

Aan die gang kom Gemiddelde mediaanmodus Standaard afwyking Persentiel Dataverspreiding Normale dataverspreiding Strooi plot Lineêre regressie Polinoomregressie Meervoudige regressie Skaal Trein/toets Besluitboom

Python MySQL

MySQL Begin MySQL Skep databasis MySQL Skep tabel MySQL-insetsel MySQL Kies MySQL Waar MySQL Bestel deur MySQL verwyder MySQL Drop Table MySQL-opdatering MySQL-limiet MySQL Sluit aan

Python MongoDB

MongoDB Begin MongoDB Skep databasis MongoDB Skep versameling MongoDB-insetsel MongoDB Vind MongoDB-navraag MongoDB Sorteer MongoDB verwyder MongoDB Drop Collection MongoDB-opdatering MongoDB-limiet

Python-verwysing

Python Oorsig Python ingeboude funksies Python-stringmetodes Python Lys Metodes Python Woordeboek Metodes Python Tuple Metodes Python Stel metodes Python-lêermetodes Python sleutelwoorde Python-uitsonderings Python Woordelys

Moduleverwysing

Ewekansige module Versoeke Module Statistiek Module Wiskunde Module cMath-module

Python Hoe om

Verwyder lys duplikate Draai 'n snaar om Voeg twee getalle by

Python voorbeelde

Python voorbeelde Python-samesteller Python-oefeninge Python Vasvra Python-sertifikaat

Matplotlib Subplotte


Wys veelvuldige erwe

Met die subplots()funksie kan jy veelvuldige plotte in een figuur teken:

Voorbeeld

Teken 2 plotte:

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()

Resultaat:


Die subplots() Funksie

Die subplots()funksie neem drie argumente wat die uitleg van die figuur beskryf.

Die uitleg is georganiseer in rye en kolomme, wat deur die eerste en tweede argument voorgestel word.

Die derde argument verteenwoordig die indeks van die huidige plot.

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.

Dus, as ons 'n figuur met 2 rye en 1 kolom wil hê (wat beteken dat die twee plotte bo-op mekaar vertoon sal word in plaas van langs mekaar), kan ons die sintaksis soos volg skryf:

Voorbeeld

Teken 2 plotte bo-op mekaar:

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()

Resultaat:

Jy kan soveel plotte wat jy wil op een figuur teken, beskryf net die aantal rye, kolomme en die indeks van die plot.

Voorbeeld

Teken 6 plotte:

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()

Resultaat:



Titel

Jy kan 'n titel by elke plot byvoeg met die title()funksie:

Voorbeeld

2 erwe, met titels:

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()

Resultaat:


Super titel

Jy kan 'n titel by die hele figuur voeg met die suptitle()funksie:

Voorbeeld

Voeg 'n titel by vir die hele figuur:

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()

Resultaat: