Python -zelfstudie

Python HOME Python-intro Python Aan de slag Python-syntaxis Python-opmerkingen Python-variabelen Python-gegevenstypen Python-nummers Python-casting Python-snaren Python Booleans Python-operators Python-lijsten Python-tupels Python-sets Python-woordenboeken Python Als...Anders Python While-lussen Python voor lussen Python-functies Python Lambda Python-arrays Python-klassen/objecten Python-overerving Python-iterators Python-bereik Python-modules Python-datums Python-wiskunde Python JSON Python RegEx Python PIP Python proberen...Behalve Python-gebruikersinvoer Opmaak van Python-tekenreeksen

Bestandsbehandeling

Python-bestandsafhandeling Python-bestanden lezen Python bestanden schrijven/maken Python bestanden verwijderen

Python-modules

NumPy-zelfstudie Panda walkthrough Scipy-zelfstudie

Python Matplotlib

Matplotlib Intro Matplotlib Aan de slag Matplotlib Pyplot Matplotlib plotten Matplotlib-markeringen Matplotlib-lijn Matplotlib-labels Matplotlib-raster Matplotlib-subplots Matplotlib Scatter Matplotlib-repen Matplotlib-histogrammen Matplotlib-cirkeldiagrammen

Machinaal leren

Beginnen Gemiddelde mediane modus Standaardafwijking percentiel Gegevensdistributie Normale gegevensverdeling Spreidingsplot Lineaire regressie Polynomiale regressie Meervoudige regressie Schaal Trein/Test Beslissingsboom

Python MySQL

MySQL Aan de slag MySQL Database maken MySQL-tabel maken MySQL-invoeging MySQL Select MySQL Waar MySQL Bestel op MySQL verwijderen MySQL-droptabel MySQL-update MySQL-limiet MySQL Join

Python MongoDB

MongoDB Aan de slag MongoDB Database maken MongoDB Verzameling maken MongoDB invoegen MongoDB Zoeken MongoDB-query MongoDB Sorteren MongoDB verwijderen MongoDB Drop-collectie MongoDB-update MongoDB-limiet

Python-referentie

Python-overzicht Ingebouwde functies van Python Python-stringmethoden Methoden voor Python-lijst Python-woordenboekmethoden Python Tuple-methoden Methoden voor Python-sets Python-bestandsmethoden Python-trefwoorden Python-uitzonderingen Python-woordenlijst

Modulereferentie

Willekeurige module Verzoekmodule Statistiekmodule Wiskundige module cMath-module

Python-instructies

Lijstduplicaten verwijderen Een string omkeren Voeg twee nummers toe

Python-voorbeelden

Python-voorbeelden Python-compiler Python-oefeningen Python-quiz Python-certificaat

Matplotlib- repen


Balken maken

Met Pyplot kunt u de bar()functie gebruiken om staafdiagrammen te tekenen:

Voorbeeld

Teken 4 staven:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x,y)
plt.show()

Resultaat:

De bar()functie heeft argumenten die de lay-out van de staven beschrijven.

De categorieën en hun waarden weergegeven door het eerste en tweede argument als arrays.

Voorbeeld

x = ["APPLES", "BANANAS"]
y = [400, 350]
plt.bar(x, y)



Horizontale balken

Als u wilt dat de balken horizontaal worden weergegeven in plaats van verticaal, gebruikt u de barh()functie:

Voorbeeld

Teken 4 horizontale balken:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.barh(x, y)
plt.show()

Resultaat:


Staafkleur

De bar()en barh()neemt het sleutelwoordargument colorom de kleur van de balken in te stellen:

Voorbeeld

Teken 4 rode balken:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x, y, color = "red")
plt.show()

Resultaat:

Kleurnamen

U kunt elk van de 140 ondersteunde kleurnamen gebruiken .

Voorbeeld

Teken 4 "felroze" balken:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x, y, color = "hotpink")
plt.show()

Resultaat:

Kleur Hex

Of u kunt hexadecimale kleurwaarden gebruiken :

Voorbeeld

Teken 4 balken met een mooie groene kleur:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x, y, color = "#4CAF50")
plt.show()

Resultaat:


Breedte staaf

Het bar()neemt het trefwoordargument widthom de breedte van de balken in te stellen:

Voorbeeld

Teken 4 zeer dunne staven:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.bar(x, y, width = 0.1)
plt.show()

Resultaat:

De standaard breedtewaarde is 0,8

Opmerking: gebruik voor horizontale balken in heightplaats van width.


Hoogte staaf

Het barh()neemt het sleutelwoordargument heightom de hoogte van de balken in te stellen:

Voorbeeld

Teken 4 zeer dunne staven:

import matplotlib.pyplot as plt
import numpy as np

x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])

plt.barh(x, y, height = 0.1)
plt.show()

Resultaat:

De standaard hoogtewaarde is 0,8