Programme für Diagrammtypen: Säule, gestapelte Säulen
Linien, gestapelte Balken, Torte
This commit is contained in:
1
teil23/.gitignore
vendored
1
teil23/.gitignore
vendored
@@ -3,3 +3,4 @@ __pycache__
|
|||||||
bin
|
bin
|
||||||
lib
|
lib
|
||||||
share
|
share
|
||||||
|
*.csv
|
||||||
|
20
teil23/iospeed_balken.py
Executable file
20
teil23/iospeed_balken.py
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encoding: utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
labels = [ 'Pineberry Pi pcie1_gen=2','Pineberry Pi pcie1_gen=3', 'MicroSD Raspi 5', 'MicroSD Raspi 4']
|
||||||
|
io_read= np.array([148.50,171.99,30.85,10.15])
|
||||||
|
io_write = np.array([99.15,114.97,20.45,6.63])
|
||||||
|
legend = ['Schreiben','Lesen']
|
||||||
|
#Höhe der Balken
|
||||||
|
__hoehe__ =0.6
|
||||||
|
|
||||||
|
fig,ax = plt.subplots()
|
||||||
|
|
||||||
|
|
||||||
|
plt.barh(labels,io_write,__hoehe__)
|
||||||
|
plt.barh(labels,io_read,__hoehe__,left=io_write)
|
||||||
|
plt.legend(legend)
|
||||||
|
plt.show()
|
||||||
|
|
30
teil23/normparabel_graph.py
Executable file
30
teil23/normparabel_graph.py
Executable file
@@ -0,0 +1,30 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
# encoding:utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def plot_normal_parabel():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -10 bis 10
|
||||||
|
x = np.linspace(-3, 3, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Normalparabel
|
||||||
|
y = x**2
|
||||||
|
|
||||||
|
# Erstelle das Diagramm
|
||||||
|
plt.plot(x, y, label='Normalparabel: $y=x^2$')
|
||||||
|
|
||||||
|
# Beschriftungen und Titel hinzufügen
|
||||||
|
plt.xlabel('x-Achse')
|
||||||
|
plt.ylabel('y-Achse')
|
||||||
|
plt.title('Normalparabel')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
# Funktion aufrufen, um die Normalparabel zu zeichnen
|
||||||
|
plot_normal_parabel()
|
||||||
|
|
||||||
|
# Diagramm anzeigen
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
45
teil23/sinus_parabel_graph.py
Executable file
45
teil23/sinus_parabel_graph.py
Executable file
@@ -0,0 +1,45 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
# encoding:utf-8
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def plot_normal_parabel():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -10 bis 10
|
||||||
|
x = np.linspace(-3, 3, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Normalparabel
|
||||||
|
y = x**2
|
||||||
|
|
||||||
|
# Erstelle das Diagramm
|
||||||
|
plt.plot(x, y, label='Normalparabel: $y=x^2$')
|
||||||
|
|
||||||
|
# Beschriftungen und Titel hinzufügen
|
||||||
|
plt.xlabel('x-Achse')
|
||||||
|
plt.ylabel('y-Achse')
|
||||||
|
plt.title('Normalparabel')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
def plot_sinus_function():
|
||||||
|
# Erzeuge Datenpunkte für x-Werte von -2π bis 2π
|
||||||
|
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
|
||||||
|
|
||||||
|
# Berechne die y-Werte für die Sinusfunktion
|
||||||
|
y = np.sin(x)
|
||||||
|
|
||||||
|
# Erstelle das Diagramm für die Sinusfunktion
|
||||||
|
plt.plot(x, y, label='Sinusfunktion: $y = \sin(x)$', color='blue')
|
||||||
|
|
||||||
|
# Legende hinzufügen
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
# Funktion aufrufen, um die Normalparabel zu zeichnen
|
||||||
|
plot_normal_parabel()
|
||||||
|
plot_sinus_function()
|
||||||
|
|
||||||
|
# Diagramm anzeigen
|
||||||
|
plt.grid(True)
|
||||||
|
plt.show()
|
23
teil23/verkauf_stapel.py
Executable file
23
teil23/verkauf_stapel.py
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encoding: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
jahre= np.array(['2018','2019', '2020'])
|
||||||
|
aepfel= np.array([1000,1500,2000])
|
||||||
|
erdbeeren =np.array([500,950,900])
|
||||||
|
bananen=np.array([400,800,750])
|
||||||
|
breite = 0.6
|
||||||
|
|
||||||
|
fig,ax = plt.subplots()
|
||||||
|
|
||||||
|
|
||||||
|
#ax.legend('Verkäufe')
|
||||||
|
ax.bar(jahre,bananen,color='yellow')
|
||||||
|
ax.bar(jahre,erdbeeren,bottom=bananen,color='red')
|
||||||
|
ax.bar(jahre,aepfel,bottom=erdbeeren,color='green')
|
||||||
|
|
||||||
|
plt.legend(['Bananen','Erdbeeren','Äpfel'])
|
||||||
|
|
||||||
|
plt.show()
|
47
teil23/vornamen_reader.py
Normal file
47
teil23/vornamen_reader.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#encoding: utf-8
|
||||||
|
|
||||||
|
def read_vornamen(filename):
|
||||||
|
dict = {}
|
||||||
|
# Der Zähler dient nur dazu, die erste Zeile zu überspringen
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
dict['mädchen'] = 0
|
||||||
|
dict['jungs'] = 0
|
||||||
|
dict['divers'] = 0
|
||||||
|
with open(filename,'r') as f:
|
||||||
|
for zeile in f:
|
||||||
|
if count >0:
|
||||||
|
# einzelne Zeile in seine Bestandteile zerlegen
|
||||||
|
splitted = zeile.strip().split(';')
|
||||||
|
anzahl = splitted[0]
|
||||||
|
vorname = splitted[1]
|
||||||
|
geschlecht= splitted[2]
|
||||||
|
position = splitted[3]
|
||||||
|
|
||||||
|
if geschlecht == 'w':
|
||||||
|
dict['mädchen'] += 1
|
||||||
|
elif geschlecht == 'm':
|
||||||
|
dict['jungs'] += 1
|
||||||
|
else:
|
||||||
|
dict['divers'] += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
data['vorname'] = vorname
|
||||||
|
data['anzahl'] = int(anzahl)
|
||||||
|
data['geschlecht'] = geschlecht
|
||||||
|
data['position'] = position
|
||||||
|
if vorname not in dict:
|
||||||
|
dict[vorname] = data
|
||||||
|
else:
|
||||||
|
# doppelte Einträge summieren wir auf.
|
||||||
|
e = dict[vorname]
|
||||||
|
e['anzahl'] = int(anzahl) + (e['anzahl'])
|
||||||
|
count +=1
|
||||||
|
|
||||||
|
gesamt = dict['jungs'] + dict['mädchen'] + dict['divers']
|
||||||
|
|
||||||
|
dict['gesamt'] = gesamt
|
||||||
|
return dict
|
||||||
|
|
42
teil23/vornamen_sauelen.py
Executable file
42
teil23/vornamen_sauelen.py
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encondig: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
from vornamen_reader import read_vornamen
|
||||||
|
|
||||||
|
|
||||||
|
def plot_geschlecht(vornamen):
|
||||||
|
|
||||||
|
bez= ['Mädchen', 'Jungs','divers']
|
||||||
|
geburten = [vornamen['mädchen'], vornamen['jungs'],vornamen['divers']]
|
||||||
|
|
||||||
|
print(f'geburten={geburten}')
|
||||||
|
|
||||||
|
farben = ['red','blue','green']
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
print(f'fig={fig}')
|
||||||
|
print(f'ax={ax}')
|
||||||
|
|
||||||
|
ax.bar(bez,geburten,label=bez, color=farben)
|
||||||
|
ax.set_ylabel('Geburten')
|
||||||
|
ax.set_title('Geburten nach Geschlecht Wuppertal 2020')
|
||||||
|
ax.legend(title='Geburten')
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
vornamen = read_vornamen('./Vornamen_Wuppertal_2020.csv')
|
||||||
|
|
||||||
|
jungs= vornamen['jungs']
|
||||||
|
maedels = vornamen['mädchen']
|
||||||
|
divers = vornamen['divers']
|
||||||
|
|
||||||
|
print(f'Jungs: {jungs}')
|
||||||
|
print(f'Mädchen: {maedels}')
|
||||||
|
print(f'divers: {divers}')
|
||||||
|
# print(f'vornamen={vornamen}')
|
||||||
|
|
||||||
|
plot_geschlecht(vornamen)
|
||||||
|
|
||||||
|
|
43
teil23/vornamen_torte.py
Executable file
43
teil23/vornamen_torte.py
Executable file
@@ -0,0 +1,43 @@
|
|||||||
|
#! ./bin/python
|
||||||
|
#encondig: utf-8
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import logging
|
||||||
|
from vornamen_reader import read_vornamen
|
||||||
|
|
||||||
|
logging.basicConfig( format='%(asctime)-15s [%(levelname)s] %(funcName)s: %(message)s', level=logging.INFO)
|
||||||
|
|
||||||
|
def plot_geschlecht(vornamen):
|
||||||
|
|
||||||
|
bez= ['Mädchen', 'Jungs','divers']
|
||||||
|
geburten = [vornamen['mädchen'], vornamen['jungs'],vornamen['divers']]
|
||||||
|
|
||||||
|
logging.info(f'geburten={geburten}')
|
||||||
|
|
||||||
|
proz_maedels = round(vornamen['mädchen'] / vornamen['gesamt'] *100,2)
|
||||||
|
proz_jungs = round(vornamen['jungs'] / vornamen['gesamt'] *100,2)
|
||||||
|
proz_divers = round(vornamen['divers'] / vornamen['gesamt'] *100,2)
|
||||||
|
|
||||||
|
farben = ['red','blue','green']
|
||||||
|
sizes= [proz_maedels,proz_jungs,proz_divers]
|
||||||
|
|
||||||
|
logging.info(f'sizes={sizes}')
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
|
||||||
|
ax.pie(sizes,explode=(0,0,0), labels=bez,autopct='%1.1f%%',shadow=True,startangle=90)
|
||||||
|
ax.axis('equal')
|
||||||
|
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
vornamen = read_vornamen('./Vornamen_Wuppertal_2020.csv')
|
||||||
|
|
||||||
|
jungs= vornamen['jungs']
|
||||||
|
maedels = vornamen['mädchen']
|
||||||
|
divers = vornamen['divers']
|
||||||
|
|
||||||
|
|
||||||
|
plot_geschlecht(vornamen)
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user