Zum Inhalt springen

„Matplotlib“ – Versionsunterschied

aus Wikipedia, der freien Enzyklopädie
[gesichtete Version][gesichtete Version]
Inhalt gelöscht Inhalt hinzugefügt
Keine Bearbeitungszusammenfassung
Beispiele: Update der Beispielplots auf aktuelle Version
Zeile 33: Zeile 33:
== Beispiele ==
== Beispiele ==
'''Kurven'''
'''Kurven'''
[[Datei:Matplotlib basic.png|rechts|rahmenlos]]
[[Datei:Matplotlib3 lineplot.svg|rechts|rahmenlos]]
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
>>> import matplotlib.pyplot as plt
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> import numpy as np
>>> a = np.linspace(0,10,100)
>>> a = np.linspace(0, 8, 501)
>>> b = np.exp(-a)
>>> b = np.exp(-a)
>>> plt.plot(a,b)
>>> plt.plot(a, b)
>>> plt.show()
>>> plt.show()
</syntaxhighlight>
</syntaxhighlight>


'''Histogramm'''
'''Histogramm'''
[[Datei:Matplotlib histogram.png|rechts|rahmenlos]]
[[Datei:Matplotlib3 histogram.svg|rechts|rahmenlos]]
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
>>> import matplotlib.pyplot as plt
>>> import matplotlib.pyplot as plt
>>> from numpy.random import normal,rand
>>> from numpy.random import normal,rand
>>> x = normal(size=200)
>>> x = normal(size=200)
>>> plt.hist(x,bins=30)
>>> plt.hist(x, bins=30, edgecolor='black')
>>> plt.show()
>>> plt.show()
</syntaxhighlight>
</syntaxhighlight>


'''Streudiagramm'''
'''Streudiagramm'''
[[Datei:Matplotlib scatter.png|rechts|rahmenlos]]
[[Datei:Matplotlib3 scatter.svg|rechts|rahmenlos]]
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
>>> import matplotlib.pyplot as plt
>>> import matplotlib.pyplot as plt
Zeile 60: Zeile 60:
>>> a = rand(100)
>>> a = rand(100)
>>> b = rand(100)
>>> b = rand(100)
>>> plt.scatter(a,b)
>>> plt.scatter(a, b, edgecolor='black')
>>> plt.show()
>>> plt.show()
</syntaxhighlight>
</syntaxhighlight>


'''3D plot'''
'''3D plot'''
[[Datei:Matplotlib 3d.png|rechts|rahmenlos]]
[[Datei:Matplotlib3 surf3d.svg|rechts|rahmenlos]]
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
>>> from matplotlib import cm
>>> from matplotlib import cm
Zeile 78: Zeile 78:
>>> R = np.sqrt(X**2 + Y**2)
>>> R = np.sqrt(X**2 + Y**2)
>>> Z = np.sin(R)
>>> Z = np.sin(R)
>>> surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm)
>>> surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, edgecolor='black')
>>> plt.show()
>>> plt.show()
</syntaxhighlight>
</syntaxhighlight>

Version vom 17. November 2020, 14:31 Uhr

Matplotlib


Eine Zusammenstellung aus fertigen Graphen und dem dazugehörigen Programmcode.
Basisdaten

Entwickler John D. Hunter
Erscheinungsjahr 2003[1]
Aktuelle Version 3.10.3[2]
(9. Mai 2025)
Betriebssystem plattformunabhängig
Programmier­sprache Python
Kategorie Programmbibliothek
Lizenz Matplotlib-Lizenz
www.matplotlib.org

Matplotlib ist eine Programmbibliothek für die Programmiersprache Python, die es erlaubt mathematische Darstellungen aller Art anzufertigen.

Beschreibung

Matplotlib kann mit Python 2.x und 3.x verwendet werden und funktioniert auf allen gängigen Betriebssystemen. Dabei wird eine Python-ähnliche objektorientierte Schnittstelle verwendet. Nach dem Importieren der Bibliothek kann man graphische Darstellungen mithilfe der Python-Konsole erzeugen. Man kann jedoch auch Matplotlib in bestehende Python-Programme integrieren. Dazu verwendet Matplotlib Anbindungen zu GUI-Bibliotheken wie GTK+, Qt, wxWidgets und Tk. Die Grafiken können in einer Vielzahl von Formaten erstellt werden, z. B.: SVG, PNG, Anti-Grain Geometry, EPS, PDF.

Matplotlib verpflichtete sich dazu, Python 2 nur noch bis zum Jahre 2020 zu unterstützen und wurde am 20. Mai 2016 in die Liste der Python-3-Erklärung aufgenommen.[3][4]

Entwicklung

Die erste Version von Matplotlib wurde von John D. Hunter in den Jahren 2002 und 2003 entwickelt.[5] Gleich zu Beginn war es als freie Open-Source-Bibliothek gedacht. Heute wird die Entwicklung auf GitHub von vielen Personen vorangetrieben.[6]

Beispiele

Kurven

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> a = np.linspace(0, 8, 501)
>>> b = np.exp(-a)
>>> plt.plot(a, b)
>>> plt.show()

Histogramm

>>> import matplotlib.pyplot as plt
>>> from numpy.random import normal,rand
>>> x = normal(size=200)
>>> plt.hist(x, bins=30, edgecolor='black')
>>> plt.show()

Streudiagramm

>>> import matplotlib.pyplot as plt
>>> from numpy.random import rand
>>> a = rand(100)
>>> b = rand(100)
>>> plt.scatter(a, b, edgecolor='black')
>>> plt.show()

3D plot

>>> from matplotlib import cm
>>> from mpl_toolkits.mplot3d import Axes3D
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> fig = plt.figure()
>>> ax = fig.gca(projection='3d')
>>> X = np.arange(-5, 5, 0.25)
>>> Y = np.arange(-5, 5, 0.25)
>>> X, Y = np.meshgrid(X, Y)
>>> R = np.sqrt(X**2 + Y**2)
>>> Z = np.sin(R)
>>> surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm, edgecolor='black')
>>> plt.show()

Weitere Beispiele

Commons: Matplotlib – Sammlung von Bildern, Videos und Audiodateien

Einzelnachweise

  1. matplotlib.org.
  2. Release 3.10.3. 9. Mai 2025 (abgerufen am 27. Mai 2025).
  3. Add matplotlib to list by takluyver · Pull Request #20 · python3statement/python3statement.github.io. In: GitHub. Abgerufen am 7. Juli 2018 (englisch).
  4. Moving to require Python 3 (englisch), auf python3statement.org, abgerufen am 17. Oktober 2018
  5. John D. Hunter: Matplotlib: A 2D Graphics Environment. In: Computing in Science & Engineering. 9. Jahrgang, Nr. 3, S. 90–95, doi:10.1109/MCSE.2007.55.
  6. Matplotlib Credits. In: Matplotlib. Matplotlib, abgerufen am 7. August 2014.