Programmierung in Python

Univ.-Prof. Dr. Martin Hepp, Universität der Bundeswehr München

Einheit 4: Datenvisualisierung

Version: 2019-12-05 -- Work in progress ;-)

http://www.ebusiness-unibw.org/wiki/Teaching/PIP

Grundlagen der Datenvisualisierung

Ziel und Probleme

Ansätze

Datenvisualisierung in Python

Matplotlib

Geschichte

Grundlagen der Anwendung

  • Beispiel
  • Anzeige in Jupyter Notebooks
  • Speichern als Datei

Ressourcen

Balkendiagramme

In [3]:
from matplotlib import pyplot as plt
plt.bar(range(5), [5, 7, 9, 3, 11])
plt.show()

Liniendiagramme

In [5]:
from matplotlib import pyplot as plt
plt.plot(range(5), [5, 7, 9, 5, 11])
plt.show()

Punktdiagramme

Vgl. auch hier.

In [18]:
from matplotlib import pyplot as plt
plt.plot(range(5), [5, 7, 9, 5, 11], '.r')
plt.show()

Boxplots

In [12]:
from matplotlib import pyplot as plt
plt.boxplot([0, 1, 5, 15, 4, 12, 5, 7, 9, 5, 11])
plt.show()

Tortendiagramme

In [16]:
# auf Basis von https://matplotlib.org/gallery/pie_and_polar_charts/pie_features.html#sphx-glr-gallery-pie-and-polar-charts-pie-features-py
import matplotlib.pyplot as plt

labels = ['Java', 'Python', 'C++', 'Javascript']
sizes = [20, 45, 15, 20]
plt.pie(sizes, labels=labels)
plt.show()

Scatter Plots

In [21]:
from matplotlib import pyplot as plt
plt.scatter([5, 7, 9, 5, 11], [5, 7, 9, 5, 11])
plt.show()

Heatmaps

In [22]:
# Beispiel aus https://stackoverflow.com/a/49608671/516699
import numpy as np
import seaborn as sns
import matplotlib.pylab as plt

uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data, linewidth=0.5)
plt.show()

Individualisierung und Gestaltung

Titel

Achsen und Achsenbeschriftungen

Farben

Legende

Mehrere Diagramme

Visualisierung von Daten mit geographischem Bezug

Landkarten etc. Vgl. z.B. hier.

Quellenangaben und weiterführende Literatur

[Pyt2019]    Python Software Foundation. Python 3.8.0 Documentation. https://docs.python.org/3/.

[Ov2019]     Ohne Verfasser. Plotting Data with Matplotlib. https://howtothink.readthedocs.io/en/latest/PvL_H.html