Changed colors for listings. Small improvements on the script.

This commit is contained in:
2015-10-28 22:36:48 +01:00
parent dbe0a2173c
commit 3ca3c7b499
10 changed files with 56 additions and 36 deletions

View File

@@ -2,8 +2,9 @@ import numpy as np
import matplotlib.pyplot as plt
# roll the die:
x1 = np.random.random_integers( 1, 6, 100 )
x2 = np.random.random_integers( 1, 6, 500 )
rng = np.random.RandomState(57281)
x1 = rng.random_integers( 1, 6, 100 )
x2 = rng.random_integers( 1, 6, 500 )
bins = np.arange(0.5, 7, 1.0)
plt.xkcd()
@@ -14,7 +15,10 @@ ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlim(0, 7)
ax.set_xticks( range(1, 7) )
ax.set_xlabel( 'x' )
ax.set_ylim(0, 98)
ax.set_ylabel( 'Frequency' )
ax.hist([x2, x1], bins, color=['#FFCC00', '#FFFF66' ])
@@ -23,9 +27,13 @@ ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlim(0, 7)
ax.set_xticks( range(1, 7) )
ax.set_xlabel( 'x' )
ax.set_ylim(0, 0.23)
ax.set_ylabel( 'Probability' )
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ])
ax.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], '-r', lw=2, zorder=1)
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ], zorder=10)
plt.tight_layout()
fig.savefig( 'diehistograms.pdf' )
#plt.show()

View File

@@ -2,9 +2,10 @@ import numpy as np
import matplotlib.pyplot as plt
# normal distribution:
rng = np.random.RandomState(6281)
x = np.arange( -4.0, 4.0, 0.01 )
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
r = np.random.randn( 100 )
r = rng.randn( 100 )
plt.xkcd()
@@ -15,9 +16,10 @@ ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_xlim(-3.2, 3.2)
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
ax.set_ylabel( 'Frequency' )
#ax.set_ylim( 0.0, 0.46 )
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
ax.set_yticks( np.arange( 0.0, 41.0, 10.0 ) )
ax.hist(r, 5, color='#CC0000')
ax.hist(r, 20, color='#FFCC00')
@@ -27,11 +29,14 @@ ax.spines['top'].set_visible(False)
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_xlim(-3.2, 3.2)
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
ax.set_ylabel( 'Probability density p(x)' )
#ax.set_ylim( 0.0, 0.46 )
#ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
ax.hist(r, 5, normed=True, color='#CC0000')
ax.hist(r, 20, normed=True, color='#FFCC00')
ax.set_ylim(0.0, 0.44)
ax.set_yticks( np.arange( 0.0, 0.41, 0.1 ) )
ax.plot(x, g, '-b', lw=2, zorder=-1)
ax.hist(r, 5, normed=True, color='#CC0000', zorder=-10)
ax.hist(r, 20, normed=True, color='#FFCC00', zorder=-5)
plt.tight_layout()
fig.savefig( 'pdfhistogram.pdf' )

View File

@@ -163,9 +163,9 @@
numbers=left,
showstringspaces=false,
language=Matlab,
commentstyle=\itshape\color{darkgray},
keywordstyle=\color{blue},
stringstyle=\color{green},
commentstyle=\itshape\color{red!60!black},
keywordstyle=\color{blue!50!black},
stringstyle=\color{green!50!black},
backgroundcolor=\color{blue!10},
breaklines=true,
breakautoindent=true,

View File

@@ -111,7 +111,8 @@ Wahrscheinlichkeitsverteilung der Messwerte ab.
to their sum.}{Histogramme des Ergebnisses von 100 oder 500 mal
W\"urfeln. Links: das absolute Histogramm z\"ahlt die Anzahl des
Auftretens jeder Augenzahl. Rechts: Normiert auf die Summe des
Histogramms werden die beiden Messungen vergleichbar.}}
Histogramms werden die beiden Messungen untereinander als auch
mit der theoretischen Verteilung $P=1/6$ vergleichbar.}}
\end{figure}
Bei ganzzahligen Messdaten (z.B. die Augenzahl eines W\"urfels)
@@ -142,7 +143,9 @@ Meistens haben wir es jedoch mit reellen Messgr\"o{\ss}en zu tun.
normalverteilten Messwerten. Links: Die H\"ohe des absoluten
Histogramms h\"angt von der Klassenbreite ab. Rechts: Bei auf
das Integral normierten Histogrammen werden auch
unterschiedliche Klassenbreiten vergleichbar.}}
unterschiedliche Klassenbreiten untereinander vergleichbar und
auch mit der theoretischen Wahrschinlichkeitsdichtefunktion
(blau).}}
\end{figure}
Histogramme von reellen Messwerten m\"ussen auf das Integral 1