# -*- coding: utf-8 -*-

import numpy as np		# Import des Modules numpy als np
import scipy as sp		# Import des Modules scipy als sp
import matplotlib.pyplot as plt # Import als plt

x = np.arange(20)
y = x**2
plt.plot(x,y)

plt.clf()

plt.xlabel("x / m") # Beschrifte X-Achse
plt.ylabel("y / $m^2$") # Beschrifte Y-Achse inkl. LaTeX-Code
plt.title("Beschrifteter Plot") # Titel des Plots
plt.xlim((x[0],x[-5]))
plt.plot(x,y,label="$x^2$") # plotte x**2 gegen x
plt.plot(x,y,linestyle=' ',marker='+',label="$x^2$ (Markers)") # plotte x**2 gegen mit Markern
plt.legend() # Füge die Legende zum Plot hinzu
plt.savefig("images/labeled.png")

plt.clf()

g = np.random.randn(3000) # Ziehe 3000 normalverteilte Zufallszahlen
plt.hist(g) # erzeuge einen Histogrammplot
h,b,p = plt.hist(g,bins=30) # erzeuge ein Histogramm mit 30 bins
print h # gib die Counts der Bins aus
print b # gib die Bins aus
plt.savefig("images/histograms.png")

plt.clf()

x = np.random.randn(3000) # Ziehe 3000 normalverteilte Zufallszahlen
y = np.random.randn(3000) # Ziehe 3000 normalverteilte Zufallszahlen
h,bx,by = np.histogram2d(x,y,bins=30) # erzeuge 2D-Histogramm
plt.pcolor(bx,by,h.T) # erzeuge Falschfarben-Plot, transponieren wegen MATLAB-Konvention\cite{mpl_pcolor}
plt.colorbar()
plt.savefig("images/pcolor.png")
plt.clf()
plt.hexbin(x,y,gridsize=30) # erzeuge Falschfarben-Plot mit hexbins
plt.colorbar()
plt.savefig("images/hexbin.png")

plt.clf()


fig = plt.figure() # Erzeuge eine neue Abbildung
axes = fig.add_subplot(111) # erzeuge einen einzelnen Plot
x = np.arange(20)
axes.plot(x,x**2)

plt.clf()

fig = plt.figure() # neue figure
ax1 = fig.add_subplot(211) # füge obere axes hinzu
ax2 = fig.add_subplot(212) # füge untere axes hinzu
x = np.arange(20)
y1 = x
y2 = x**2
ax1.plot(x,y1)
ax2.plot(x,y2)
fig.savefig("images/multiplot.png")

plt.clf()
