merge
This commit is contained in:
commit
4e7373da38
@ -1,8 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
|
||||||
fig = plt.figure( figsize=(6,3.5) )
|
|
||||||
rng = np.random.RandomState(637281)
|
rng = np.random.RandomState(637281)
|
||||||
|
|
||||||
nsamples = 100
|
nsamples = 100
|
||||||
@ -25,11 +24,8 @@ for i in range(nresamples) :
|
|||||||
musrs.append(np.mean(rng.randn(nsamples)))
|
musrs.append(np.mean(rng.randn(nsamples)))
|
||||||
hmusrs, _ = np.histogram(musrs, bins, density=True)
|
hmusrs, _ = np.histogram(musrs, bins, density=True)
|
||||||
|
|
||||||
ax = fig.add_subplot(1, 1, 1)
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
ax.spines['right'].set_visible(False)
|
fig.subplots_adjust(**adjust_fs(left=4.0, bottom=2.7, right=1.5))
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.set_xlabel('Mean')
|
ax.set_xlabel('Mean')
|
||||||
ax.set_xlim(-0.4, 0.4)
|
ax.set_xlim(-0.4, 0.4)
|
||||||
ax.set_ylabel('Probability density')
|
ax.set_ylabel('Probability density')
|
||||||
@ -45,9 +41,7 @@ ax.annotate('bootstrap\ndistribution',
|
|||||||
xytext=(0.25, 4), textcoords='data',
|
xytext=(0.25, 4), textcoords='data',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=20,angleB=60") )
|
connectionstyle="angle3,angleA=20,angleB=60") )
|
||||||
ax.bar(bins[:-1]-0.25*db, hmusrs, 0.5*db, color='r')
|
ax.bar(bins[:-1]-0.25*db, hmusrs, 0.5*db, **fsB)
|
||||||
ax.bar(bins[:-1]+0.25*db, hmus, 0.5*db, color='b')
|
ax.bar(bins[:-1]+0.25*db, hmus, 0.5*db, **fsA)
|
||||||
|
|
||||||
plt.tight_layout()
|
|
||||||
plt.savefig('bootstrapsem.pdf')
|
plt.savefig('bootstrapsem.pdf')
|
||||||
#plt.show();
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.stats as st
|
import scipy.stats as st
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
|
||||||
fig = plt.figure( figsize=(6,3.5) )
|
|
||||||
rng = np.random.RandomState(637281)
|
rng = np.random.RandomState(637281)
|
||||||
|
|
||||||
# generate correlated data:
|
# generate correlated data:
|
||||||
@ -36,11 +35,8 @@ print('Measured correlation coefficient %.2f is at %.4f percentile of bootstrap'
|
|||||||
rp, ra = st.pearsonr(x, y)
|
rp, ra = st.pearsonr(x, y)
|
||||||
print('Measured correlation coefficient %.2f is at %.4f percentile of test' % (rp, ra))
|
print('Measured correlation coefficient %.2f is at %.4f percentile of test' % (rp, ra))
|
||||||
|
|
||||||
ax = fig.add_subplot(1, 1, 1)
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
ax.spines['right'].set_visible(False)
|
fig.subplots_adjust(**adjust_fs(left=4.0, bottom=2.7, right=0.5, top=1.0))
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.annotate('Measured\ncorrelation\nis significant!',
|
ax.annotate('Measured\ncorrelation\nis significant!',
|
||||||
xy=(rd, 1.1), xycoords='data',
|
xy=(rd, 1.1), xycoords='data',
|
||||||
xytext=(rd, 2.2), textcoords='data', ha='left',
|
xytext=(rd, 2.2), textcoords='data', ha='left',
|
||||||
@ -56,13 +52,11 @@ ax.annotate('Distribution of\nuncorrelated\nsamples',
|
|||||||
xytext=(-0.22, 5.0), textcoords='data', ha='left',
|
xytext=(-0.22, 5.0), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
||||||
connectionstyle="angle3,angleA=150,angleB=100") )
|
connectionstyle="angle3,angleA=150,angleB=100") )
|
||||||
ax.bar(b[:-1], h, width=b[1]-b[0], color='#ffff66')
|
ax.bar(b[:-1], h, width=b[1]-b[0], **fsC)
|
||||||
ax.bar(b[:-1][b[:-1]>=rq], h[b[:-1]>=rq], width=b[1]-b[0], color='#ff9900')
|
ax.bar(b[:-1][b[:-1]>=rq], h[b[:-1]>=rq], width=b[1]-b[0], **fsB)
|
||||||
ax.plot( [rd, rd], [0, 1], 'b', linewidth=4 )
|
ax.plot( [rd, rd], [0, 1], **lsA)
|
||||||
ax.set_xlim(-0.25, 0.35)
|
ax.set_xlim(-0.25, 0.35)
|
||||||
ax.set_xlabel('Correlation coefficient')
|
ax.set_xlabel('Correlation coefficient')
|
||||||
ax.set_ylabel('Probability density of H0')
|
ax.set_ylabel('Probability density of H0')
|
||||||
|
|
||||||
plt.tight_layout()
|
|
||||||
plt.savefig('permutecorrelation.pdf')
|
plt.savefig('permutecorrelation.pdf')
|
||||||
#plt.show();
|
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import matplotlib.cm as cm
|
import matplotlib.cm as cm
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
|
||||||
fig = plt.figure( figsize=(6,6.8) )
|
|
||||||
rng = np.random.RandomState(4637281)
|
rng = np.random.RandomState(4637281)
|
||||||
lmarg=0.1
|
lmarg=0.1
|
||||||
rmarg=0.1
|
rmarg=0.1
|
||||||
|
|
||||||
ax = fig.add_axes([lmarg, 0.75, 1.0-rmarg, 0.25])
|
fig = plt.figure(figsize=cm_size(figure_width, 2.8*figure_height))
|
||||||
ax.spines['bottom'].set_position('zero')
|
spec = gridspec.GridSpec(nrows=4, ncols=1, height_ratios=[4, 4, 1, 3], hspace=0.2,
|
||||||
ax.spines['left'].set_visible(False)
|
**adjust_fs(fig, left=4.0))
|
||||||
ax.spines['right'].set_visible(False)
|
ax = fig.add_subplot(spec[0, 0])
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.get_yaxis().set_visible(False)
|
|
||||||
ax.set_xlim(0.0, np.pi)
|
ax.set_xlim(0.0, np.pi)
|
||||||
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
||||||
ax.set_xticklabels([])
|
ax.set_xticklabels([])
|
||||||
ax.set_ylim(0.0, 3.5)
|
ax.set_ylim(0.0, 3.5)
|
||||||
|
ax.yaxis.set_major_locator(plt.NullLocator())
|
||||||
ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center')
|
ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center')
|
||||||
ax.annotate('Tuning curve',
|
ax.annotate('Tuning curve',
|
||||||
xy=(0.42*np.pi, 2.5), xycoords='data',
|
xy=(0.42*np.pi, 2.5), xycoords='data',
|
||||||
@ -31,55 +29,49 @@ ax.annotate('',
|
|||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
||||||
connectionstyle="angle3,angleA=80,angleB=90") )
|
connectionstyle="angle3,angleA=80,angleB=90") )
|
||||||
ax.text(0.52*np.pi, 0.7, 'preferred\norientation')
|
ax.text(0.52*np.pi, 0.7, 'preferred\norientation')
|
||||||
ax.plot([0, 0], [0.0, 3.5], 'k', zorder=10, clip_on=False)
|
|
||||||
xx = np.arange(0.0, 2.0*np.pi, 0.01)
|
xx = np.arange(0.0, 2.0*np.pi, 0.01)
|
||||||
pp = 0.5*np.pi
|
pp = 0.5*np.pi
|
||||||
yy = np.exp(np.cos(2.0*(xx+pp)))
|
yy = np.exp(np.cos(2.0*(xx+pp)))
|
||||||
ax.fill_between(xx, yy+0.25*yy, yy-0.25*yy, color=cm.autumn(0.3, 1), alpha=0.5)
|
ax.fill_between(xx, yy+0.25*yy, yy-0.25*yy, **fsBa)
|
||||||
ax.plot(xx, yy, color=cm.autumn(0.0, 1))
|
ax.plot(xx, yy, **lsB)
|
||||||
|
|
||||||
ax = fig.add_axes([lmarg, 0.34, 1.0-rmarg, 0.38])
|
ax = fig.add_subplot(spec[1, 0])
|
||||||
ax.spines['bottom'].set_position('zero')
|
|
||||||
ax.spines['left'].set_visible(False)
|
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.get_yaxis().set_visible(False)
|
|
||||||
ax.set_xlim(0.0, np.pi)
|
ax.set_xlim(0.0, np.pi)
|
||||||
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
||||||
ax.set_xticklabels([])
|
ax.set_xticklabels([])
|
||||||
ax.set_ylim(-1.5, 3.0)
|
ax.set_ylim(0.0, 3.0)
|
||||||
ax.text(0.5*np.pi, -1.8, 'Orientation', ha='center')
|
ax.yaxis.set_major_locator(plt.NullLocator())
|
||||||
ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center')
|
ax.text(-0.2, 0.5*3.5, 'Activity', rotation='vertical', va='center')
|
||||||
ax.plot([0, 0], [0.0, 3.0], 'k', zorder=10, clip_on=False)
|
|
||||||
xx = np.arange(0.0, 1.0*np.pi, 0.01)
|
xx = np.arange(0.0, 1.0*np.pi, 0.01)
|
||||||
prefphases = np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi)
|
prefphases = np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi)
|
||||||
responses = []
|
responses = []
|
||||||
xresponse = 0.475*np.pi
|
xresponse = 0.475*np.pi
|
||||||
for pp in prefphases :
|
for pp, ls, ps in zip(prefphases, [lsE, lsC, lsD, lsB, lsD, lsC, lsE],
|
||||||
|
[psE, psC, psD, psB, psD, psC, psE]) :
|
||||||
yy = np.exp(np.cos(2.0*(xx+pp)))
|
yy = np.exp(np.cos(2.0*(xx+pp)))
|
||||||
ax.plot(xx, yy, color=cm.autumn(2.0*np.abs(pp/np.pi-0.5), 1))
|
#ax.plot(xx, yy, color=cm.autumn(2.0*np.abs(pp/np.pi-0.5), 1))
|
||||||
|
ax.plot(xx, yy, **ls)
|
||||||
y = np.exp(np.cos(2.0*(xresponse+pp)))
|
y = np.exp(np.cos(2.0*(xresponse+pp)))
|
||||||
responses.append(y + rng.randn()*0.25*y)
|
responses.append(y + rng.randn()*0.25*y)
|
||||||
ax.plot(xresponse, y, '.', markersize=20, color=cm.autumn(2.0*np.abs(pp/np.pi-0.5), 1))
|
ax.plot(xresponse, y, **ps)
|
||||||
r=0.3
|
|
||||||
y=-0.8
|
|
||||||
ax.plot([pp-0.5*r*np.cos(pp), pp+0.5*r*np.cos(pp)], [y-r*np.sin(pp), y+r*np.sin(pp)], 'k', lw=6)
|
|
||||||
responses = np.array(responses)
|
responses = np.array(responses)
|
||||||
|
|
||||||
ax = fig.add_axes([lmarg, 0.05, 1.0-rmarg, 0.22])
|
ax = fig.add_subplot(spec[2, 0])
|
||||||
ax.spines['left'].set_visible(False)
|
ax.show_spines('')
|
||||||
ax.spines['right'].set_visible(False)
|
r = 0.3
|
||||||
ax.spines['top'].set_visible(False)
|
ax.set_ylim(-1.1*r, 1.1*r)
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
for pp in prefphases:
|
||||||
ax.get_yaxis().set_visible(False)
|
ax.plot([pp-0.5*r*np.cos(pp), pp+0.5*r*np.cos(pp)], [-r*np.sin(pp), r*np.sin(pp)],
|
||||||
|
colors['black'], lw=6, clip_on=False)
|
||||||
|
|
||||||
|
ax = fig.add_subplot(spec[3, 0])
|
||||||
ax.set_xlim(0.0, np.pi)
|
ax.set_xlim(0.0, np.pi)
|
||||||
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
ax.set_xticks(np.arange(0.125*np.pi, 1.*np.pi, 0.125*np.pi))
|
||||||
ax.set_xticklabels([])
|
ax.set_xticklabels([])
|
||||||
ax.set_ylim(-1600, 0)
|
ax.set_ylim(-1600, 0)
|
||||||
|
ax.yaxis.set_major_locator(plt.NullLocator())
|
||||||
ax.set_xlabel('Orientation')
|
ax.set_xlabel('Orientation')
|
||||||
ax.text(-0.2, -800, 'Log-Likelihood', rotation='vertical', va='center')
|
ax.text(-0.2, -800, 'Log-Likelihood', rotation='vertical', va='center')
|
||||||
ax.plot([0, 0], [-1600, 0], 'k', zorder=10, clip_on=False)
|
|
||||||
phases = np.linspace(0.0, 1.1*np.pi, 100)
|
phases = np.linspace(0.0, 1.1*np.pi, 100)
|
||||||
probs = np.zeros((len(responses), len(phases)))
|
probs = np.zeros((len(responses), len(phases)))
|
||||||
for k, (pp, r) in enumerate(zip(prefphases, responses)) :
|
for k, (pp, r) in enumerate(zip(prefphases, responses)) :
|
||||||
@ -95,7 +87,6 @@ ax.annotate('',
|
|||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
||||||
connectionstyle="angle3,angleA=80,angleB=90") )
|
connectionstyle="angle3,angleA=80,angleB=90") )
|
||||||
ax.text(maxp+0.05, -1100, 'most likely\norientation\ngiven the responses')
|
ax.text(maxp+0.05, -1100, 'most likely\norientation\ngiven the responses')
|
||||||
ax.plot(phases, loglikelihood, '-b')
|
ax.plot(phases, loglikelihood, **lsA)
|
||||||
|
|
||||||
plt.savefig('mlecoding.pdf')
|
plt.savefig('mlecoding.pdf')
|
||||||
#plt.show();
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
fig = plt.figure(figsize=cm_size(figure_width, 1.8*figure_height))
|
||||||
fig = plt.figure( figsize=(6,5) )
|
spec = gridspec.GridSpec(nrows=2, ncols=2, hspace=0.6,
|
||||||
|
**adjust_fs(fig, left=5.5))
|
||||||
|
|
||||||
# the data:
|
# the data:
|
||||||
n = 40
|
n = 40
|
||||||
@ -17,11 +20,7 @@ g=np.zeros((len(x), len(mus)))
|
|||||||
for k, mu in enumerate(mus) :
|
for k, mu in enumerate(mus) :
|
||||||
g[:,k] = np.exp(-0.5*((x-mu)/sigma)**2.0)/np.sqrt(2.0*np.pi)/sigma
|
g[:,k] = np.exp(-0.5*((x-mu)/sigma)**2.0)/np.sqrt(2.0*np.pi)/sigma
|
||||||
# plot it:
|
# plot it:
|
||||||
ax = fig.add_subplot( 2, 1, 1 )
|
ax = fig.add_subplot(spec[0, :])
|
||||||
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.5, 3.5)
|
ax.set_xlim(0.5, 3.5)
|
||||||
ax.set_ylim(-0.02, 0.85)
|
ax.set_ylim(-0.02, 0.85)
|
||||||
ax.set_xticks(np.arange(0, 5))
|
ax.set_xticks(np.arange(0, 5))
|
||||||
@ -41,9 +40,9 @@ for mu in mus :
|
|||||||
ax.text(mu-0.1, 0.04, '?', zorder=1, ha='right')
|
ax.text(mu-0.1, 0.04, '?', zorder=1, ha='right')
|
||||||
else :
|
else :
|
||||||
ax.text(mu+0.1, 0.04, '?', zorder=1)
|
ax.text(mu+0.1, 0.04, '?', zorder=1)
|
||||||
for k in range(len(mus)) :
|
for k, ls in enumerate([lsCm, lsBm, lsDm]) :
|
||||||
ax.plot(x, g[:,k], zorder=5)
|
ax.plot(x, g[:,k], zorder=5, **ls)
|
||||||
ax.scatter(xd, 0.05*rng.rand(len(xd))+0.2, s=30, zorder=10)
|
ax.plot(xd, 0.05*rng.rand(len(xd))+0.2, zorder=10, **psAm)
|
||||||
|
|
||||||
# likelihood:
|
# likelihood:
|
||||||
thetas=np.arange(1.5, 2.6, 0.01)
|
thetas=np.arange(1.5, 2.6, 0.01)
|
||||||
@ -52,11 +51,7 @@ for i, theta in enumerate(thetas) :
|
|||||||
ps[:,i]=np.exp(-0.5*((xd-theta)/sigma)**2.0)/np.sqrt(2.0*np.pi)/sigma
|
ps[:,i]=np.exp(-0.5*((xd-theta)/sigma)**2.0)/np.sqrt(2.0*np.pi)/sigma
|
||||||
p=np.prod(ps,axis=0)
|
p=np.prod(ps,axis=0)
|
||||||
# plot it:
|
# plot it:
|
||||||
ax = fig.add_subplot( 2, 2, 3 )
|
ax = fig.add_subplot(spec[1, 0])
|
||||||
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_xlabel(r'Parameter $\theta$')
|
ax.set_xlabel(r'Parameter $\theta$')
|
||||||
ax.set_ylabel('Likelihood')
|
ax.set_ylabel('Likelihood')
|
||||||
ax.set_xticks(np.arange(1.6, 2.5, 0.4))
|
ax.set_xticks(np.arange(1.6, 2.5, 0.4))
|
||||||
@ -70,13 +65,9 @@ ax.annotate('',
|
|||||||
xytext=(2.0, 5e-11), textcoords='data',
|
xytext=(2.0, 5e-11), textcoords='data',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
||||||
connectionstyle="angle3,angleA=90,angleB=80"))
|
connectionstyle="angle3,angleA=90,angleB=80"))
|
||||||
ax.plot(thetas,p)
|
ax.plot(thetas, p, **lsAm)
|
||||||
|
|
||||||
ax = fig.add_subplot( 2, 2, 4 )
|
ax = fig.add_subplot(spec[1, 1])
|
||||||
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_xlabel(r'Parameter $\theta$')
|
ax.set_xlabel(r'Parameter $\theta$')
|
||||||
ax.set_ylabel('Log-Likelihood')
|
ax.set_ylabel('Log-Likelihood')
|
||||||
ax.set_ylim(-50,-20)
|
ax.set_ylim(-50,-20)
|
||||||
@ -92,8 +83,6 @@ ax.annotate('',
|
|||||||
xytext=(2.0, -26), textcoords='data',
|
xytext=(2.0, -26), textcoords='data',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.5),
|
||||||
connectionstyle="angle3,angleA=80,angleB=100"))
|
connectionstyle="angle3,angleA=80,angleB=100"))
|
||||||
ax.plot(thetas,np.log(p))
|
ax.plot(thetas,np.log(p), **lsAm)
|
||||||
|
|
||||||
plt.tight_layout();
|
|
||||||
plt.savefig('mlemean.pdf')
|
plt.savefig('mlemean.pdf')
|
||||||
#plt.show();
|
|
||||||
|
@ -2,9 +2,10 @@ import numpy as np
|
|||||||
import scipy.stats as st
|
import scipy.stats as st
|
||||||
import scipy.optimize as opt
|
import scipy.optimize as opt
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
fig = plt.figure( figsize=(6,3) )
|
fig.subplots_adjust(**adjust_fs(fig, right=1.0))
|
||||||
|
|
||||||
# the data:
|
# the data:
|
||||||
n = 100
|
n = 100
|
||||||
@ -23,27 +24,23 @@ a = st.gamma.fit(xd, 5.0)
|
|||||||
yf = st.gamma.pdf(xx, *a)
|
yf = st.gamma.pdf(xx, *a)
|
||||||
|
|
||||||
# plot it:
|
# plot it:
|
||||||
ax = fig.add_subplot( 1, 2, 1 )
|
ax1.set_xlim(0, 10.0)
|
||||||
ax.spines['right'].set_visible(False)
|
ax1.set_ylim(0.0, 0.42)
|
||||||
ax.spines['top'].set_visible(False)
|
ax1.set_xticks(np.arange(0, 11, 2))
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax1.set_yticks(np.arange(0, 0.42, 0.1))
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax1.set_xlabel('x')
|
||||||
ax.set_xlim(0, 10.0)
|
ax1.set_ylabel('Probability density')
|
||||||
ax.set_ylim(0.0, 0.42)
|
ax1.plot(xx, yy, label='pdf', **lsB)
|
||||||
ax.set_xticks( np.arange(0, 11, 2))
|
ax1.plot(xx, yf, label='mle', **lsCm)
|
||||||
ax.set_yticks( np.arange(0, 0.42, 0.1))
|
|
||||||
ax.set_xlabel('x')
|
|
||||||
ax.set_ylabel('Probability density')
|
|
||||||
ax.plot(xx, yy, '-', lw=5, color='#ff0000', label='pdf')
|
|
||||||
ax.plot(xx, yf, '-', lw=2, color='#ffcc00', label='mle')
|
|
||||||
kernel = st.gaussian_kde(xd)
|
kernel = st.gaussian_kde(xd)
|
||||||
x = kernel(xd)
|
x = kernel(xd)
|
||||||
x /= np.max(x)
|
x /= np.max(x)
|
||||||
ax.scatter(xd, 0.05*x*(rng.rand(len(xd))-0.5)+0.05, s=30, zorder=10)
|
sigma = 0.07
|
||||||
ax.legend(loc='upper right', frameon=False)
|
ax1.plot(xd, sigma*x*(rng.rand(len(xd))-0.5)+sigma, zorder=10, **psAm)
|
||||||
|
ax1.legend(loc='upper right')
|
||||||
|
|
||||||
# histogram:
|
# histogram:
|
||||||
h,b = np.histogram(xd, np.arange(0, 8.5, 1), density=True)
|
h,b = np.histogram(xd, np.arange(0, 8.4, 0.5), density=True)
|
||||||
|
|
||||||
# fit histogram:
|
# fit histogram:
|
||||||
def gammapdf(x, n, l, s) :
|
def gammapdf(x, n, l, s) :
|
||||||
@ -52,22 +49,15 @@ popt, pcov = opt.curve_fit(gammapdf, b[:-1]+0.5*(b[1]-b[0]), h)
|
|||||||
yc = st.gamma.pdf(xx, *popt)
|
yc = st.gamma.pdf(xx, *popt)
|
||||||
|
|
||||||
# plot it:
|
# plot it:
|
||||||
ax = fig.add_subplot( 1, 2, 2 )
|
ax2.set_xlim(0, 10.0)
|
||||||
ax.spines['right'].set_visible(False)
|
ax2.set_xticks(np.arange(0, 11, 2))
|
||||||
ax.spines['top'].set_visible(False)
|
ax2.set_xlabel('x')
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax2.set_ylim(0.0, 0.42)
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax2.set_yticks(np.arange(0, 0.42, 0.1))
|
||||||
ax.set_xlim(0, 10.0)
|
ax2.set_ylabel('Probability density')
|
||||||
ax.set_xticks( np.arange(0, 11, 2))
|
ax2.plot(xx, yy, label='pdf', **lsB)
|
||||||
ax.set_xlabel('x')
|
ax2.plot(xx, yc, label='fit', **lsCm)
|
||||||
ax.set_ylim(0.0, 0.42)
|
ax2.bar(b[:-1], h, np.diff(b), **fsA)
|
||||||
ax.set_yticks( np.arange(0, 0.42, 0.1))
|
ax2.legend(loc='upper right')
|
||||||
ax.set_ylabel('Probability density')
|
|
||||||
ax.plot(xx, yy, '-', lw=5, color='#ff0000', label='pdf')
|
|
||||||
ax.plot(xx, yc, '-', lw=2, color='#ffcc00', label='fit')
|
|
||||||
ax.bar(b[:-1], h, np.diff(b))
|
|
||||||
ax.legend(loc='upper right', frameon=False)
|
|
||||||
|
|
||||||
plt.tight_layout();
|
|
||||||
plt.savefig('mlepdf.pdf')
|
plt.savefig('mlepdf.pdf')
|
||||||
#plt.show();
|
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.stats as st
|
import scipy.stats as st
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
fig = plt.figure()
|
||||||
fig = plt.figure(figsize=(6, 3))
|
spec = gridspec.GridSpec(nrows=1, ncols=2, wspace=0.3,
|
||||||
|
**adjust_fs(fig, left=5.5))
|
||||||
|
spec1 = gridspec.GridSpecFromSubplotSpec(1, 2, spec[0, 0], width_ratios=[3, 1], wspace=0.0)
|
||||||
|
spec2 = gridspec.GridSpecFromSubplotSpec(1, 2, spec[0, 1], width_ratios=[3, 1], wspace=0.0)
|
||||||
|
|
||||||
# the line:
|
# the line:
|
||||||
slope = 2.0
|
slope = 2.0
|
||||||
@ -20,71 +25,44 @@ slopef = np.sum(x*y)/np.sum(x*x)
|
|||||||
yf = slopef*xx
|
yf = slopef*xx
|
||||||
|
|
||||||
# plot it:
|
# plot it:
|
||||||
ax = fig.add_axes([0.09, 0.02, 0.33, 0.9])
|
ax = fig.add_subplot(spec1[0, 0])
|
||||||
ax.spines['left'].set_position('zero')
|
|
||||||
ax.spines['bottom'].set_position('zero')
|
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.get_xaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.get_yaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.set_xticks(np.arange(0.0, 4.1))
|
ax.set_xticks(np.arange(0.0, 4.1))
|
||||||
ax.set_xlim(0.0, 4.2)
|
ax.set_xlim(0.0, 4.2)
|
||||||
ax.set_ylim(-4.0, 12.0)
|
ax.set_ylim(-4.0, 12.0)
|
||||||
ax.set_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_ylabel('y')
|
ax.set_ylabel('y')
|
||||||
ax.scatter(x, y, label='data', s=40, zorder=10)
|
ax.plot(x, y, label='data', zorder=10, **psAm)
|
||||||
ax.plot(xx, yy, 'r', lw=5.0, color='#ff0000', label='original', zorder=5)
|
ax.plot(xx, yy, label='original', zorder=5, **lsB)
|
||||||
ax.plot(xx, yf, '--', lw=1.0, color='#ffcc00', label='fit', zorder=7)
|
ax.plot(xx, yf, label='fit', zorder=7, **lsCm)
|
||||||
ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.15), frameon=False)
|
ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.15))
|
||||||
|
|
||||||
ax = fig.add_axes([0.42, 0.02, 0.07, 0.9])
|
ax = fig.add_subplot(spec1[0, 1])
|
||||||
ax.spines['left'].set_position('zero')
|
ax.show_spines('l')
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.spines['bottom'].set_visible(False)
|
|
||||||
ax.get_yaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.set_xticks([])
|
ax.set_xticks([])
|
||||||
ax.set_ylim(-4.0, 12.0)
|
ax.set_ylim(-4.0, 12.0)
|
||||||
ax.set_yticks([])
|
ax.set_yticks([])
|
||||||
bins = np.arange(-4.0, 12.1, 0.75)
|
bins = np.arange(-4.0, 12.1, 0.75)
|
||||||
ax.hist(y, bins, orientation='horizontal', zorder=10)
|
ax.hist(y, bins, orientation='horizontal', zorder=10, **fsA)
|
||||||
|
|
||||||
ax = fig.add_axes([0.6, 0.02, 0.33, 0.9])
|
ax = fig.add_subplot(spec2[0, 0])
|
||||||
ax.spines['left'].set_position('zero')
|
|
||||||
ax.spines['bottom'].set_position('zero')
|
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.get_xaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.get_yaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.set_xticks(np.arange(0.0, 4.1))
|
ax.set_xticks(np.arange(0.0, 4.1))
|
||||||
ax.set_xlim(0.0, 4.2)
|
ax.set_xlim(0.0, 4.2)
|
||||||
ax.set_ylim(-4.0, 12.0)
|
ax.set_ylim(-4.0, 12.0)
|
||||||
ax.set_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_ylabel('y - mx')
|
ax.set_ylabel('y - mx')
|
||||||
ax.scatter(x, y - slopef*x, label='residuals', s=40, zorder=10)
|
ax.plot(x, y - slopef*x, label='residuals', zorder=10, **psAm)
|
||||||
#ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.0), frameon=False)
|
#ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.0))
|
||||||
|
|
||||||
ax = fig.add_axes([0.93, 0.02, 0.07, 0.9])
|
ax = fig.add_subplot(spec2[0, 1])
|
||||||
ax.spines['left'].set_position('zero')
|
ax.show_spines('l')
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.spines['bottom'].set_visible(False)
|
|
||||||
ax.get_yaxis().set_tick_params(direction='inout', length=10, width=2)
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.set_xlim(0.0, 11.0)
|
ax.set_xlim(0.0, 11.0)
|
||||||
ax.set_xticks([])
|
ax.set_xticks([])
|
||||||
ax.set_ylim(-4.0, 12.0)
|
ax.set_ylim(-4.0, 12.0)
|
||||||
ax.set_yticks([])
|
ax.set_yticks([])
|
||||||
r = y - slopef*x
|
r = y - slopef*x
|
||||||
ax.hist(r, bins, orientation='horizontal', zorder=10)
|
ax.hist(r, bins, orientation='horizontal', zorder=10, **fsA)
|
||||||
gx = np.arange(-4.0, 12.1, 0.1)
|
gx = np.arange(-4.0, 12.1, 0.1)
|
||||||
gy = st.norm.pdf(gx, np.mean(r), np.std(r))
|
gy = st.norm.pdf(gx, np.mean(r), np.std(r))
|
||||||
ax.plot(1.0+gy*29.0, gx, 'r', lw=2, zorder=5)
|
ax.plot(1.0+gy*29.0, gx, zorder=5, **lsBm)
|
||||||
|
|
||||||
plt.savefig('mlepropline.pdf')
|
plt.savefig('mlepropline.pdf')
|
||||||
#plt.show();
|
|
||||||
|
225
plotstyle.py
225
plotstyle.py
@ -1,6 +1,5 @@
|
|||||||
import matplotlib as mpl
|
import matplotlib as mpl
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from cycler import cycler
|
|
||||||
from mpl_toolkits.mplot3d import Axes3D
|
from mpl_toolkits.mplot3d import Axes3D
|
||||||
|
|
||||||
xkcd_style = False
|
xkcd_style = False
|
||||||
@ -13,125 +12,103 @@ figure_height = 6.0 # cm, for a 1 x 2 figure
|
|||||||
ppi = 72.0
|
ppi = 72.0
|
||||||
|
|
||||||
# colors:
|
# colors:
|
||||||
|
colors = {}
|
||||||
def lighter(color, lightness):
|
colors['red'] = '#DD1000'
|
||||||
""" Make a color lighter.
|
colors['orange'] = '#FF9900'
|
||||||
|
colors['lightorange'] = '#FFCC00'
|
||||||
Parameters
|
colors['yellow'] = '#FFF720'
|
||||||
----------
|
colors['green'] = '#99FF00'
|
||||||
color: string
|
colors['blue'] = '#0010CC'
|
||||||
An RGB color as a hexadecimal string (e.g. '#rrggbb').
|
colors['gray'] = '#A7A7A7'
|
||||||
lightness: float
|
colors['black'] = '#000000'
|
||||||
The smaller the lightness, the lighter the returned color.
|
colors['white'] = '#FFFFFF'
|
||||||
A lightness of 1 leaves the color untouched.
|
|
||||||
A lightness of 0 returns white.
|
#colors_bendalab_vivid['green'] = '#30D700'
|
||||||
|
#colors_bendalab_vivid['blue'] = '#0020C0'
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
color: string
|
|
||||||
The lighter color as a hexadecimal RGB string (e.g. '#rrggbb').
|
|
||||||
"""
|
|
||||||
r = int(color[1:3], 16)
|
|
||||||
g = int(color[3:5], 16)
|
|
||||||
b = int(color[5:7], 16)
|
|
||||||
rl = r + (1.0-lightness)*(0xff - r)
|
|
||||||
gl = g + (1.0-lightness)*(0xff - g)
|
|
||||||
bl = b + (1.0-lightness)*(0xff - b)
|
|
||||||
return '#%02X%02X%02X' % (rl, gl, bl)
|
|
||||||
|
|
||||||
|
|
||||||
def darker(color, saturation):
|
|
||||||
""" Make a color darker.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
color: string
|
|
||||||
An RGB color as a hexadecimal string (e.g. '#rrggbb').
|
|
||||||
saturation: float
|
|
||||||
The smaller the saturation, the darker the returned color.
|
|
||||||
A saturation of 1 leaves the color untouched.
|
|
||||||
A saturation of 0 returns black.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
color: string
|
|
||||||
The darker color as a hexadecimal RGB string (e.g. '#rrggbb').
|
|
||||||
"""
|
|
||||||
r = int(color[1:3], 16)
|
|
||||||
g = int(color[3:5], 16)
|
|
||||||
b = int(color[5:7], 16)
|
|
||||||
rd = r * saturation
|
|
||||||
gd = g * saturation
|
|
||||||
bd = b * saturation
|
|
||||||
return '#%02X%02X%02X' % (rd, gd, bd)
|
|
||||||
|
|
||||||
|
|
||||||
# colors:
|
|
||||||
colors = {
|
|
||||||
'red': '#CC0000',
|
|
||||||
'orange': '#FF9900',
|
|
||||||
'lightorange': '#FFCC00',
|
|
||||||
'yellow': '#FFFF66',
|
|
||||||
'green': '#99FF00',
|
|
||||||
'blue': '#0000CC'
|
|
||||||
}
|
|
||||||
|
|
||||||
""" Muted colors used by the Benda-lab. """
|
|
||||||
colors_bendalab = {}
|
|
||||||
colors_bendalab['red'] = '#C02010'
|
|
||||||
colors_bendalab['orange'] = '#F78010'
|
|
||||||
colors_bendalab['yellow'] = '#F0D730'
|
|
||||||
colors_bendalab['green'] = '#A0B717'
|
|
||||||
colors_bendalab['cyan'] = '#40A787'
|
|
||||||
colors_bendalab['blue'] = '#2757A0'
|
|
||||||
colors_bendalab['purple'] = '#573790'
|
|
||||||
colors_bendalab['pink'] = '#C72750'
|
|
||||||
colors_bendalab['grey'] = '#A0A0A0'
|
|
||||||
colors_bendalab['black'] = '#000000'
|
|
||||||
|
|
||||||
""" Vivid colors used by the Benda-lab. """
|
|
||||||
colors_bendalab_vivid = {}
|
|
||||||
colors_bendalab_vivid['red'] = '#D71000'
|
|
||||||
colors_bendalab_vivid['orange'] = '#FF9000'
|
|
||||||
colors_bendalab_vivid['yellow'] = '#FFF700'
|
|
||||||
colors_bendalab_vivid['green'] = '#30D700'
|
|
||||||
colors_bendalab_vivid['cyan'] = '#00F0B0'
|
|
||||||
colors_bendalab_vivid['blue'] = '#0020C0'
|
|
||||||
colors_bendalab_vivid['purple'] = '#B000B0'
|
|
||||||
colors_bendalab_vivid['pink'] = '#F00080'
|
|
||||||
colors_bendalab_vivid['grey'] = '#A7A7A7'
|
|
||||||
colors_bendalab_vivid['black'] = '#000000'
|
|
||||||
|
|
||||||
# colors for the plots of the script:
|
|
||||||
colors = colors_bendalab_vivid
|
|
||||||
colors['lightorange'] = colors['yellow']
|
|
||||||
#colors['yellow'] = lighter(colors['yellow'], 0.65)
|
|
||||||
colors['yellow'] = '#FFFF55'
|
|
||||||
|
|
||||||
# line styles for plot():
|
# line styles for plot():
|
||||||
lsSpine = {'c': colors['black'], 'linestyle': '-', 'linewidth': 1}
|
lwthick = 3.0
|
||||||
lsGrid = {'c': colors['grey'], 'linestyle': '--', 'linewidth': 1}
|
lwthin = 1.8
|
||||||
|
mainline = {'linestyle': '-', 'linewidth': lwthick}
|
||||||
# 'B1': prominent line with first color and style from color group 'B'
|
minorline = {'linestyle': '-', 'linewidth': lwthin}
|
||||||
# 'C2m': minor line with second color and style from color group 'C'
|
largemarker = {'marker': 'o', 'markersize': 9, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
|
||||||
ls = {
|
smallmarker = {'marker': 'o', 'markersize': 6, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
|
||||||
'A1': {'c': colors['red'], 'linestyle': '-', 'linewidth': 3},
|
largelinepoints = {'linestyle': '-', 'linewidth': lwthick, 'marker': 'o', 'markersize': 10, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
|
||||||
'A2': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 3},
|
smalllinepoints = {'linestyle': '-', 'linewidth': 1.4, 'marker': 'o', 'markersize': 7, 'markeredgecolor': colors['white'], 'markeredgewidth': 1}
|
||||||
'A3': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 3},
|
filllw = 1
|
||||||
'B1': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 3},
|
fillec = colors['white']
|
||||||
'B2': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 3},
|
fillalpha = 0.4
|
||||||
'B3': {'c': colors['yellow'], 'linestyle': '-', 'linewidth': 3},
|
|
||||||
'C1': {'c': colors['green'], 'linestyle': '-', 'linewidth': 3},
|
# helper lines:
|
||||||
'D1': {'c': colors['blue'], 'linestyle': '-', 'linewidth': 3},
|
lsSpine = {'c': colors['black'], 'linestyle': '-', 'linewidth': 1, 'clip_on': False}
|
||||||
'A1m': {'c': colors['red'], 'linestyle': '-', 'linewidth': 2},
|
lsGrid = {'c': colors['gray'], 'linestyle': '--', 'linewidth': 1}
|
||||||
'A2m': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 2},
|
lsMarker = {'c': colors['black'], 'linestyle': '-', 'linewidth': 2}
|
||||||
'A3m': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 2},
|
|
||||||
'B1m': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 2},
|
# line (ls), point (ps), and fill styles (fs).
|
||||||
'B2m': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 2},
|
|
||||||
'B3m': {'c': colors['yellow'], 'linestyle': '-', 'linewidth': 2},
|
# Each style is derived from a main color as indicated by the capital letter.
|
||||||
'C1m': {'c': colors['green'], 'linestyle': '-', 'linewidth': 2},
|
|
||||||
'D1m': {'c': colors['blue'], 'linestyle': '-', 'linewidth': 2},
|
# Line styles come in two variants:
|
||||||
}
|
# - plain style with a thick/solid line (e.g. lsA), and
|
||||||
|
# - minor style with a thinner or dashed line (e.g. lsAm).
|
||||||
|
|
||||||
|
# Point (marker) styles come in two variants:
|
||||||
|
# - plain style with large solid markers (e.g. psB), and
|
||||||
|
# - minor style with smaller markers (e.g. psBm).
|
||||||
|
|
||||||
|
# Linepoint styles (markers connected by lines) come in two variants:
|
||||||
|
# - plain style with large solid markers (e.g. lpsA), and
|
||||||
|
# - minor style with smaller markers (e.g. lpsAm).
|
||||||
|
|
||||||
|
# Fill styles come in three variants:
|
||||||
|
# - plain (e.g. fsB) for a solid fill color and a darker edge color,
|
||||||
|
# - solid (e.g. fsBs) for a solid fill color and without edge color, and
|
||||||
|
# - alpha (e.g. fsBa) for a transparent fill color without edge color.
|
||||||
|
|
||||||
|
lsA = dict({'color': colors['blue']}, **mainline)
|
||||||
|
lsAm = dict({'color': colors['blue']}, **minorline)
|
||||||
|
psA = dict({'color': colors['blue'], 'linestyle': 'none'}, **largemarker)
|
||||||
|
psAm = dict({'color': colors['blue'], 'linestyle': 'none'}, **smallmarker)
|
||||||
|
lpsA = dict({'color': colors['blue']}, **largelinepoints)
|
||||||
|
lpsAm = dict({'color': colors['blue']}, **smalllinepoints)
|
||||||
|
fsA = {'facecolor': colors['blue'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsAs = {'facecolor': colors['blue'], 'edgecolor': 'none'}
|
||||||
|
fsAa = {'facecolor': colors['blue'], 'edgecolor': 'none', 'alpha': fillalpha}
|
||||||
|
|
||||||
|
lsB = dict({'color': colors['red']}, **mainline)
|
||||||
|
lsBm = dict({'color': colors['red']}, **minorline)
|
||||||
|
psB = dict({'color': colors['red'], 'linestyle': 'none'}, **largemarker)
|
||||||
|
psBm = dict({'color': colors['red'], 'linestyle': 'none'}, **smallmarker)
|
||||||
|
lpsB = dict({'color': colors['red']}, **largelinepoints)
|
||||||
|
lpsBm = dict({'color': colors['red']}, **smalllinepoints)
|
||||||
|
fsB = {'facecolor': colors['red'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsBs = {'facecolor': colors['red'], 'edgecolor': 'none'}
|
||||||
|
fsBa = {'facecolor': colors['red'], 'edgecolor': 'none', 'alpha': fillalpha}
|
||||||
|
|
||||||
|
lsC = dict({'color': colors['lightorange']}, **mainline)
|
||||||
|
lsCm = dict({'color': colors['lightorange']}, **minorline)
|
||||||
|
psC = dict({'color': colors['lightorange'], 'linestyle': 'none'}, **largemarker)
|
||||||
|
psCm = dict({'color': colors['lightorange'], 'linestyle': 'none'}, **smallmarker)
|
||||||
|
fsC = {'facecolor': colors['lightorange'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsCs = {'facecolor': colors['lightorange'], 'edgecolor': 'none'}
|
||||||
|
fsCa = {'facecolor': colors['lightorange'], 'edgecolor': 'none', 'alpha': fillalpha}
|
||||||
|
|
||||||
|
lsD = dict({'color': colors['orange']}, **mainline)
|
||||||
|
lsDm = dict({'color': colors['orange']}, **minorline)
|
||||||
|
psD = dict({'color': colors['orange'], 'linestyle': 'none'}, **largemarker)
|
||||||
|
psDm = dict({'color': colors['orange'], 'linestyle': 'none'}, **smallmarker)
|
||||||
|
fsD = {'facecolor': colors['orange'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsDs = {'facecolor': colors['orange'], 'edgecolor': 'none'}
|
||||||
|
|
||||||
|
lsE = dict({'color': colors['yellow']}, **mainline)
|
||||||
|
lsEm = dict({'color': colors['yellow']}, **minorline)
|
||||||
|
psE = dict({'color': colors['yellow'], 'linestyle': 'none'}, **largemarker)
|
||||||
|
psEm = dict({'color': colors['yellow'], 'linestyle': 'none'}, **smallmarker)
|
||||||
|
fsE = {'facecolor': colors['yellow'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsEs = {'facecolor': colors['yellow'], 'edgecolor': 'none'}
|
||||||
|
|
||||||
|
fsF = {'facecolor': colors['green'], 'edgecolor': fillec, 'linewidth': filllw}
|
||||||
|
fsFs = {'facecolor': colors['green'], 'edgecolor': 'none'}
|
||||||
|
|
||||||
# factor for scaling widths of bars in a bar plot:
|
# factor for scaling widths of bars in a bar plot:
|
||||||
bar_fac = 1.0
|
bar_fac = 1.0
|
||||||
@ -364,19 +341,19 @@ def common_format():
|
|||||||
mpl.rcParams['grid.color'] = lsGrid['c']
|
mpl.rcParams['grid.color'] = lsGrid['c']
|
||||||
mpl.rcParams['grid.linestyle'] = lsGrid['linestyle']
|
mpl.rcParams['grid.linestyle'] = lsGrid['linestyle']
|
||||||
mpl.rcParams['grid.linewidth'] = lsGrid['linewidth']
|
mpl.rcParams['grid.linewidth'] = lsGrid['linewidth']
|
||||||
|
mpl.rcParams['legend.frameon'] = False
|
||||||
mpl.rcParams['axes.facecolor'] = 'none'
|
mpl.rcParams['axes.facecolor'] = 'none'
|
||||||
mpl.rcParams['axes.edgecolor'] = lsSpine['c']
|
mpl.rcParams['axes.edgecolor'] = lsSpine['c']
|
||||||
mpl.rcParams['axes.linewidth'] = lsSpine['linewidth']
|
mpl.rcParams['axes.linewidth'] = lsSpine['linewidth']
|
||||||
if 'axes.prop_cycle' in mpl.rcParams:
|
if 'axes.prop_cycle' in mpl.rcParams:
|
||||||
|
from cycler import cycler
|
||||||
mpl.rcParams['axes.prop_cycle'] = cycler(color=[colors['blue'], colors['red'],
|
mpl.rcParams['axes.prop_cycle'] = cycler(color=[colors['blue'], colors['red'],
|
||||||
colors['orange'], colors['green'],
|
colors['lightorange'], colors['orange'],
|
||||||
colors['purple'], colors['yellow'],
|
colors['yellow'], colors['green']])
|
||||||
colors['cyan'], colors['pink']])
|
|
||||||
else:
|
else:
|
||||||
mpl.rcParams['axes.color_cycle'] = [colors['blue'], colors['red'],
|
mpl.rcParams['axes.color_cycle'] = [colors['blue'], colors['red'],
|
||||||
colors['orange'], colors['green'],
|
colors['lightorange'], colors['orange'],
|
||||||
colors['purple'], colors['yellow'],
|
colors['yellow'], colors['green']]
|
||||||
colors['cyan'], colors['pink']]
|
|
||||||
# overwrite axes constructor:
|
# overwrite axes constructor:
|
||||||
if not hasattr(mpl.axes.Subplot, '__init__orig'):
|
if not hasattr(mpl.axes.Subplot, '__init__orig'):
|
||||||
mpl.axes.Subplot.__init__orig = mpl.axes.Subplot.__init__
|
mpl.axes.Subplot.__init__orig = mpl.axes.Subplot.__init__
|
||||||
|
@ -1,94 +1,104 @@
|
|||||||
|
For new projects:
|
||||||
|
Copy project_template/ and adapt according to your needs
|
||||||
|
|
||||||
All projects:
|
All projects:
|
||||||
|
|
||||||
check for time information
|
check for time information
|
||||||
|
|
||||||
|
|
||||||
|
1) project_activation_curve
|
||||||
|
medium
|
||||||
|
Write questions
|
||||||
|
|
||||||
project_adaptation_fit
|
2) project_adaptation_fit
|
||||||
OK, medium
|
OK, medium
|
||||||
Add plotting of cost function
|
Add plotting of cost function
|
||||||
|
|
||||||
project_eod
|
3) project_eod
|
||||||
OK, medium - difficult
|
OK, medium - difficult
|
||||||
b_0 is not defined
|
b_0 is not defined
|
||||||
|
|
||||||
project_eyetracker
|
4) project_eyetracker
|
||||||
OK, difficult
|
OK, difficult
|
||||||
no statistics, but kmeans
|
no statistics, but kmeans
|
||||||
|
|
||||||
project_fano_slope
|
5) project_face_selectivity
|
||||||
|
medium-difficult
|
||||||
|
(Marius monkey data)
|
||||||
|
|
||||||
|
6) project_fano_slope
|
||||||
OK, difficult
|
OK, difficult
|
||||||
|
|
||||||
project_fano_test
|
7) project_fano_test
|
||||||
OK -
|
OK -
|
||||||
|
|
||||||
project_fano_time
|
8) project_fano_time
|
||||||
OK, medium-difficult
|
OK, medium-difficult
|
||||||
|
|
||||||
project_ficurves
|
9) project_ficurves
|
||||||
OK, medium
|
OK, medium
|
||||||
Maybe add correlation test or fit statistics
|
Maybe add correlation test or fit statistics
|
||||||
|
|
||||||
project_input_resistance
|
10) project_input_resistance
|
||||||
medium
|
medium
|
||||||
What is the problem with this project? --> No difference between segments
|
What is the problem with this project? --> No difference between segments
|
||||||
Improve questions
|
Improve questions
|
||||||
|
|
||||||
project_isicorrelations
|
11) project_isicorrelations
|
||||||
medium-difficult
|
medium-difficult
|
||||||
Need to finish solution
|
Need to finish solution
|
||||||
|
|
||||||
project_isipdffit
|
12) project_isipdffit
|
||||||
Too technical
|
Too technical
|
||||||
|
|
||||||
project_lif
|
13) project_lif
|
||||||
OK, difficult
|
OK, difficult
|
||||||
no statistics
|
no statistics
|
||||||
|
|
||||||
project_mutualinfo
|
14) project_mutualinfo
|
||||||
OK, medium
|
OK, medium
|
||||||
|
|
||||||
project_noiseficurves
|
15) project_noiseficurves
|
||||||
OK, simple-medium
|
OK, simple-medium
|
||||||
no statistics
|
no statistics
|
||||||
|
|
||||||
project_numbers
|
16) project_numbers
|
||||||
simple
|
simple
|
||||||
We might add some more involved statistical analysis
|
We might add some more involved statistical analysis
|
||||||
|
|
||||||
project_pca_natural_images
|
17) project_pca_natural_images
|
||||||
medium
|
medium
|
||||||
Make a solution (->Lukas)
|
Make a solution (->Lukas)
|
||||||
|
|
||||||
project_photoreceptor
|
18) project_photoreceptor
|
||||||
OK, simple
|
OK, simple
|
||||||
|
|
||||||
project_populationvector
|
19) project_populationvector
|
||||||
difficult
|
difficult
|
||||||
OK
|
OK
|
||||||
|
|
||||||
project_qvalues
|
20) project_power_analysis
|
||||||
|
medium
|
||||||
|
|
||||||
|
21) project_qvalues
|
||||||
-
|
-
|
||||||
Interesting! But needs solution.
|
Interesting! But needs solution.
|
||||||
|
|
||||||
project_random_walk
|
22) project_random_walk
|
||||||
simple-medium
|
simple-medium
|
||||||
|
|
||||||
project_serialcorrelation
|
23) project_serialcorrelation
|
||||||
OK, simple-medium
|
OK, simple-medium
|
||||||
|
|
||||||
project_spectra
|
24) project_shorttermpotentiation
|
||||||
|
Write questions
|
||||||
|
|
||||||
|
25) project_spectra
|
||||||
-
|
-
|
||||||
Needs improvements and a solution
|
Needs improvements and a solution
|
||||||
|
|
||||||
project_stimulus_reconstruction
|
26) project_stimulus_reconstruction
|
||||||
OK, difficult
|
OK, difficult
|
||||||
|
|
||||||
project_vector_strength
|
27) project_vector_strength
|
||||||
OK, medium-difficult
|
OK, medium-difficult
|
||||||
|
|
||||||
project_power_analysis
|
|
||||||
medium
|
|
||||||
|
|
||||||
Marius monkey data:
|
|
||||||
medium-difficult
|
|
@ -14,7 +14,7 @@
|
|||||||
\section{Estimation of the activation curve}
|
\section{Estimation of the activation curve}
|
||||||
Mutations in genes, encoding for ion channels, can result in a variety of neurological diseases like epilepsy, autism and intellectual disability. One way to find a possible treatment is to compare the voltage dependent kinetics of the mutated channel with its corresponding wild-type. These kinetics are described in voltage-clamp experiments and the subsequent data analysis.
|
Mutations in genes, encoding for ion channels, can result in a variety of neurological diseases like epilepsy, autism and intellectual disability. One way to find a possible treatment is to compare the voltage dependent kinetics of the mutated channel with its corresponding wild-type. These kinetics are described in voltage-clamp experiments and the subsequent data analysis.
|
||||||
|
|
||||||
In this task you will compute and compare the activation curves of the Nav1.6 wild-type channel and one with a mutation named A1622D (the amino acid Alanine (A) at the 1622nd position is replaced by Aspartic acid (D)) that causes intellectual disability in humans.
|
In this task you will compute and compare the activation curves of the Nav1.6 wild-type channel and a variation named A1622D (the amino acid Alanine (A) at the 1622nd position is replaced by Aspartic acid (D)) that causes intellectual disability in humans.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ def create_data():
|
|||||||
|
|
||||||
|
|
||||||
def plot_data(ax, x, y, c):
|
def plot_data(ax, x, y, c):
|
||||||
ax.scatter(x, y, marker='o', color=colors['blue'], s=40, zorder=10)
|
ax.plot(x, y, zorder=10, **psAm)
|
||||||
xx = np.linspace(2.1, 3.9, 100)
|
xx = np.linspace(2.1, 3.9, 100)
|
||||||
ax.plot(xx, c*xx**3.0, color=colors['red'], lw=2, zorder=5)
|
ax.plot(xx, c*xx**3.0, zorder=5, **lsBm)
|
||||||
for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]:
|
for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]:
|
||||||
ax.plot(xx, cc*xx**3.0, color=colors['orange'], lw=1.5, zorder=5)
|
ax.plot(xx, cc*xx**3.0, zorder=5, **lsDm)
|
||||||
ax.set_xlabel('Size x', 'm')
|
ax.set_xlabel('Size x', 'm')
|
||||||
ax.set_ylabel('Weight y', 'kg')
|
ax.set_ylabel('Weight y', 'kg')
|
||||||
ax.set_xlim(2, 4)
|
ax.set_xlim(2, 4)
|
||||||
@ -42,15 +42,15 @@ def plot_data_errors(ax, x, y, c):
|
|||||||
xytext=(3.4, 70), textcoords='data', ha='left',
|
xytext=(3.4, 70), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0),
|
||||||
connectionstyle="angle3,angleA=50,angleB=-30") )
|
connectionstyle="angle3,angleA=50,angleB=-30") )
|
||||||
ax.scatter(x[:40], y[:40], color=colors['blue'], s=10, zorder=0)
|
ax.plot(x[:40], y[:40], zorder=0, **psAm)
|
||||||
inxs = [3, 10, 11, 17, 18, 21, 28, 30, 33]
|
inxs = [3, 10, 11, 17, 18, 21, 28, 30, 33]
|
||||||
ax.scatter(x[inxs], y[inxs], color=colors['blue'], s=40, zorder=10)
|
ax.plot(x[inxs], y[inxs], zorder=10, **psA)
|
||||||
xx = np.linspace(2.1, 3.9, 100)
|
xx = np.linspace(2.1, 3.9, 100)
|
||||||
ax.plot(xx, c*xx**3.0, color=colors['red'], lw=2)
|
ax.plot(xx, c*xx**3.0, **lsBm)
|
||||||
for i in inxs :
|
for i in inxs :
|
||||||
xx = [x[i], x[i]]
|
xx = [x[i], x[i]]
|
||||||
yy = [c*x[i]**3.0, y[i]]
|
yy = [c*x[i]**3.0, y[i]]
|
||||||
ax.plot(xx, yy, color=colors['orange'], lw=2, zorder=5)
|
ax.plot(xx, yy, zorder=5, **lsDm)
|
||||||
|
|
||||||
def plot_error_hist(ax, x, y, c):
|
def plot_error_hist(ax, x, y, c):
|
||||||
ax.set_xlabel('Squared error')
|
ax.set_xlabel('Squared error')
|
||||||
@ -67,7 +67,7 @@ def plot_error_hist(ax, x, y, c):
|
|||||||
xytext=(800, 3), textcoords='data', ha='left',
|
xytext=(800, 3), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
||||||
connectionstyle="angle3,angleA=10,angleB=90") )
|
connectionstyle="angle3,angleA=10,angleB=90") )
|
||||||
ax.hist(errors, bins, color=colors['orange'])
|
ax.hist(errors, bins, **fsC)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@ if __name__ == "__main__":
|
|||||||
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.4*figure_height))
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.4*figure_height))
|
||||||
fig.subplots_adjust(**adjust_fs(left=6.0, right=1.2))
|
fig.subplots_adjust(**adjust_fs(left=6.0, right=1.2))
|
||||||
|
|
||||||
ax.scatter(x, y, marker='o', color=colors['blue'], s=40, zorder=10)
|
ax.plot(x, y, zorder=10, **psA)
|
||||||
xx = np.linspace(2.1, 3.9, 100)
|
xx = np.linspace(2.1, 3.9, 100)
|
||||||
ax.plot(xx, c*xx**3.0, color=colors['red'], lw=3, zorder=5)
|
ax.plot(xx, c*xx**3.0, zorder=5, **lsB)
|
||||||
for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]:
|
for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]:
|
||||||
ax.plot(xx, cc*xx**3.0, color=colors['orange'], lw=2, zorder=5)
|
ax.plot(xx, cc*xx**3.0, zorder=5, **lsDm)
|
||||||
ax.set_xlabel('Size x', 'm')
|
ax.set_xlabel('Size x', 'm')
|
||||||
ax.set_ylabel('Weight y', 'kg')
|
ax.set_ylabel('Weight y', 'kg')
|
||||||
ax.set_xlim(2, 4)
|
ax.set_xlim(2, 4)
|
||||||
|
@ -39,9 +39,9 @@ def plot_mse(ax, x, y, c, cs):
|
|||||||
for i, cc in enumerate(ccs):
|
for i, cc in enumerate(ccs):
|
||||||
mses[i] = np.mean((y-(cc*x**3.0))**2.0)
|
mses[i] = np.mean((y-(cc*x**3.0))**2.0)
|
||||||
|
|
||||||
ax.plot(ccs, mses, colors['blue'], lw=2, zorder=10)
|
ax.plot(ccs, mses, zorder=10, **lsAm)
|
||||||
ax.scatter(cs, ms, color=colors['red'], s=40, zorder=20)
|
ax.plot(cs[:12], ms[:12], zorder=20, **psB)
|
||||||
ax.scatter(cs[-1], ms[-1], color=colors['orange'], s=60, zorder=30)
|
ax.plot(cs[-1], ms[-1], zorder=30, **psC)
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
ax.annotate('',
|
ax.annotate('',
|
||||||
xy=(cs[i+1]+0.2, ms[i+1]), xycoords='data',
|
xy=(cs[i+1]+0.2, ms[i+1]), xycoords='data',
|
||||||
@ -56,12 +56,12 @@ def plot_mse(ax, x, y, c, cs):
|
|||||||
ax.set_yticks(np.arange(0, 30001, 10000))
|
ax.set_yticks(np.arange(0, 30001, 10000))
|
||||||
|
|
||||||
def plot_descent(ax, cs, mses):
|
def plot_descent(ax, cs, mses):
|
||||||
ax.plot(np.arange(len(mses))+1, mses, '-o', c=colors['red'], mew=0, ms=8)
|
ax.plot(np.arange(len(mses))+1, mses, **lpsBm)
|
||||||
ax.set_xlabel('Iteration')
|
ax.set_xlabel('Iteration')
|
||||||
#ax.set_ylabel('Mean squared error')
|
#ax.set_ylabel('Mean squared error')
|
||||||
ax.set_xlim(0, 10.5)
|
ax.set_xlim(0, 12.5)
|
||||||
ax.set_ylim(0, 25000)
|
ax.set_ylim(0, 25000)
|
||||||
ax.set_xticks(np.arange(0.0, 10.1, 2.0))
|
ax.set_xticks(np.arange(0.0, 12.1, 2.0))
|
||||||
ax.set_yticks(np.arange(0, 30001, 10000))
|
ax.set_yticks(np.arange(0, 30001, 10000))
|
||||||
ax.set_yticklabels([])
|
ax.set_yticklabels([])
|
||||||
|
|
||||||
|
@ -4,8 +4,7 @@ from plotstyle import *
|
|||||||
|
|
||||||
plain_style()
|
plain_style()
|
||||||
|
|
||||||
fig = plt.figure( figsize=(2.5,3.4) )
|
fig, ax = plt.subplots(figsize=(2.5,3.4))
|
||||||
ax = fig.add_subplot(1, 1, 1)
|
|
||||||
|
|
||||||
# parabula:
|
# parabula:
|
||||||
x1 = -0.2
|
x1 = -0.2
|
||||||
@ -14,7 +13,7 @@ x = np.linspace(x1, x2, 200)
|
|||||||
y = x*x
|
y = x*x
|
||||||
ax.set_xlim(x1, x2)
|
ax.set_xlim(x1, x2)
|
||||||
ax.set_ylim(-0.2, 0.7)
|
ax.set_ylim(-0.2, 0.7)
|
||||||
ax.plot(x, y, c=colors['blue'], lw=4, zorder=0)
|
ax.plot(x, y, zorder=0, **lsA)
|
||||||
# secant:
|
# secant:
|
||||||
x = np.asarray([0.1, 0.7])
|
x = np.asarray([0.1, 0.7])
|
||||||
y = x*x
|
y = x*x
|
||||||
@ -22,33 +21,33 @@ ax.set_xticks(x)
|
|||||||
ax.set_yticks(y)
|
ax.set_yticks(y)
|
||||||
ax.set_xticklabels(['$x$','$x+\Delta x$'])
|
ax.set_xticklabels(['$x$','$x+\Delta x$'])
|
||||||
ax.set_yticklabels(['',''])
|
ax.set_yticklabels(['',''])
|
||||||
ax.scatter(x, y, c=colors['red'], edgecolor='none', s=150, zorder=10)
|
ax.plot(x, y, zorder=10, **psB)
|
||||||
# function values:
|
# function values:
|
||||||
ax.plot([x[0], x[0], x1],[-0.2, y[0], y[0]], '--k', lw=1, zorder=6)
|
ax.plot([x[0], x[0], x1],[-0.2, y[0], y[0]], zorder=6, **lsGrid)
|
||||||
ax.plot([x[1], x[1], x1],[-0.2, y[1], y[1]], '--k', lw=1, zorder=6)
|
ax.plot([x[1], x[1], x1],[-0.2, y[1], y[1]], zorder=6, **lsGrid)
|
||||||
ax.text(x1+0.05, y[0]+0.05, '$f(x)$', zorder=6)
|
ax.text(x1+0.05, y[0]+0.05, '$f(x)$', zorder=6)
|
||||||
ax.text(x1+0.05, y[1]+0.05, '$f(x+\Delta x)$', zorder=6)
|
ax.text(x1+0.05, y[1]+0.05, '$f(x+\Delta x)$', zorder=6)
|
||||||
# slope triangle:
|
# slope triangle:
|
||||||
ax.plot([x[0], x[1], x[1]],[y[0], y[0], y[1]], '-k', lw=2, zorder=7)
|
ax.plot([x[0], x[1], x[1]],[y[0], y[0], y[1]], zorder=7, **lsMarker)
|
||||||
ax.text(np.mean(x), y[0]-0.08, '$\Delta x$', ha='center', zorder=7)
|
ax.text(np.mean(x), y[0]-0.07, '$\Delta x$', ha='center', zorder=7)
|
||||||
ax.text(x[1]+0.05, np.mean(y), '$f(x+\Delta x)-f(x)$', va='center', rotation='vertical', zorder=7)
|
ax.text(x[1]+0.05, np.mean(y), '$f(x+\Delta x)-f(x)$', va='center', rotation='vertical', zorder=7)
|
||||||
# secant line:
|
# secant line:
|
||||||
m = np.diff(y)/np.diff(x)
|
m = np.diff(y)/np.diff(x)
|
||||||
xl = [x1, x2]
|
xl = [x1, x2]
|
||||||
yl = m*(xl-x[0])+y[0]
|
yl = m*(xl-x[0])+y[0]
|
||||||
ax.plot(xl, yl, c=colors['red'], lw=3, zorder=7)
|
ax.plot(xl, yl, zorder=7, **lsBm)
|
||||||
|
|
||||||
# derivative:
|
# derivative:
|
||||||
md = 2.0*x[0]
|
md = 2.0*x[0]
|
||||||
yl = md*(xl-x[0])+y[0]
|
yl = md*(xl-x[0])+y[0]
|
||||||
ax.plot(xl, yl, c=colors['yellow'], lw=3, zorder=5)
|
ax.plot(xl, yl, zorder=5, **lsDm)
|
||||||
|
|
||||||
# limit:
|
# limit:
|
||||||
for ml in np.linspace(md, m, 5)[1:] :
|
for ml in np.linspace(md, m, 5)[1:] :
|
||||||
yl = ml*(xl-x[0])+y[0]
|
yl = ml*(xl-x[0])+y[0]
|
||||||
xs = 0.5*(ml+np.sqrt(ml*ml-4.0*(ml*x[0]-y[0])))
|
xs = 0.5*(ml+np.sqrt(ml*ml-4.0*(ml*x[0]-y[0])))
|
||||||
ax.scatter([xs], [xs*xs], c=colors['orange'], edgecolor='none', s=80, zorder=3)
|
ax.plot([xs], [xs*xs], zorder=3, **psC)
|
||||||
ax.plot(xl, yl, c=colors['orange'], lw=2, zorder=3)
|
ax.plot(xl, yl, zorder=3, **lsCm)
|
||||||
|
|
||||||
fig.subplots_adjust(**adjust_fs(fig, 0.5, 0.5, 1.4, 0.5))
|
fig.subplots_adjust(**adjust_fs(fig, 0.5, 0.5, 1.4, 0.5))
|
||||||
plt.savefig('derivative.pdf')
|
plt.savefig('derivative.pdf')
|
||||||
|
@ -14,7 +14,7 @@ def create_data():
|
|||||||
|
|
||||||
|
|
||||||
def plot_data(ax, x, y):
|
def plot_data(ax, x, y):
|
||||||
ax.scatter(x, y, marker='o', color=colors['blue'], s=40)
|
ax.plot(x, y, **psA)
|
||||||
ax.set_xlabel('Input x')
|
ax.set_xlabel('Input x')
|
||||||
ax.set_ylabel('Output y')
|
ax.set_ylabel('Output y')
|
||||||
ax.set_xlim(0, 120)
|
ax.set_xlim(0, 120)
|
||||||
@ -24,10 +24,10 @@ def plot_data(ax, x, y):
|
|||||||
|
|
||||||
|
|
||||||
def plot_data_slopes(ax, x, y, m, n):
|
def plot_data_slopes(ax, x, y, m, n):
|
||||||
ax.scatter(x, y, marker='o', color=colors['blue'], s=40)
|
ax.plot(x, y, **psA)
|
||||||
xx = np.asarray([2, 118])
|
xx = np.asarray([2, 118])
|
||||||
for i in np.linspace(0.3*m, 2.0*m, 5):
|
for i in np.linspace(0.3*m, 2.0*m, 5):
|
||||||
ax.plot(xx, i*xx+n, color=colors['red'], lw=2)
|
ax.plot(xx, i*xx+n, **lsBm)
|
||||||
ax.set_xlabel('Input x')
|
ax.set_xlabel('Input x')
|
||||||
#ax.set_ylabel('Output y')
|
#ax.set_ylabel('Output y')
|
||||||
ax.set_xlim(0, 120)
|
ax.set_xlim(0, 120)
|
||||||
@ -37,10 +37,10 @@ def plot_data_slopes(ax, x, y, m, n):
|
|||||||
|
|
||||||
|
|
||||||
def plot_data_intercepts(ax, x, y, m, n):
|
def plot_data_intercepts(ax, x, y, m, n):
|
||||||
ax.scatter(x, y, marker='o', color=colors['blue'], s=40)
|
ax.plot(x, y, **psA)
|
||||||
xx = np.asarray([2, 118])
|
xx = np.asarray([2, 118])
|
||||||
for i in np.linspace(n-1*n, n+1*n, 5):
|
for i in np.linspace(n-1*n, n+1*n, 5):
|
||||||
ax.plot(xx, m*xx + i, color=colors['red'], lw=2)
|
ax.plot(xx, m*xx + i, **lsBm)
|
||||||
ax.set_xlabel('Input x')
|
ax.set_xlabel('Input x')
|
||||||
#ax.set_ylabel('Output y')
|
#ax.set_ylabel('Output y')
|
||||||
ax.set_xlim(0, 120)
|
ax.set_xlim(0, 120)
|
||||||
|
@ -25,15 +25,15 @@ def plot_data(ax, x, y, m, n):
|
|||||||
xytext=(80, -50), textcoords='data', ha='left',
|
xytext=(80, -50), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.9,1.0),
|
||||||
connectionstyle="angle3,angleA=50,angleB=-30") )
|
connectionstyle="angle3,angleA=50,angleB=-30") )
|
||||||
ax.scatter(x[:40], y[:40], color=colors['blue'], s=10, zorder=0)
|
ax.plot(x[:40], y[:40], zorder=0, **psAm)
|
||||||
inxs = [3, 13, 16, 19, 25, 34, 36]
|
inxs = [3, 13, 16, 19, 25, 34, 36]
|
||||||
ax.scatter(x[inxs], y[inxs], color=colors['blue'], s=40, zorder=10)
|
ax.plot(x[inxs], y[inxs], zorder=10, **psA)
|
||||||
xx = np.asarray([2, 118])
|
xx = np.asarray([2, 118])
|
||||||
ax.plot(xx, m*xx+n, color=colors['red'], lw=2)
|
ax.plot(xx, m*xx+n, **lsBm)
|
||||||
for i in inxs :
|
for i in inxs :
|
||||||
xx = [x[i], x[i]]
|
xx = [x[i], x[i]]
|
||||||
yy = [m*x[i]+n, y[i]]
|
yy = [m*x[i]+n, y[i]]
|
||||||
ax.plot(xx, yy, color=colors['orange'], lw=2, zorder=5)
|
ax.plot(xx, yy, zorder=5, **lsDm)
|
||||||
|
|
||||||
|
|
||||||
def plot_error_hist(ax, x, y, m, n):
|
def plot_error_hist(ax, x, y, m, n):
|
||||||
@ -51,7 +51,7 @@ def plot_error_hist(ax, x, y, m, n):
|
|||||||
xytext=(350, 20), textcoords='data', ha='left',
|
xytext=(350, 20), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
||||||
connectionstyle="angle3,angleA=10,angleB=90") )
|
connectionstyle="angle3,angleA=10,angleB=90") )
|
||||||
ax.hist(errors, bins, color=colors['orange'])
|
ax.hist(errors, bins, **fsD)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ if __name__ == "__main__":
|
|||||||
spec = gridspec.GridSpec(nrows=1, ncols=2, width_ratios=[3, 1], wspace=0.08,
|
spec = gridspec.GridSpec(nrows=1, ncols=2, width_ratios=[3, 1], wspace=0.08,
|
||||||
**adjust_fs(fig, left=6.0))
|
**adjust_fs(fig, left=6.0))
|
||||||
ax1 = fig.add_subplot(spec[0, 0])
|
ax1 = fig.add_subplot(spec[0, 0])
|
||||||
ax1.scatter(indices, data, c=colors['blue'], edgecolor='white', s=50)
|
ax1.plot(indices, data, **psAm)
|
||||||
ax1.set_xlabel('Index')
|
ax1.set_xlabel('Index')
|
||||||
ax1.set_ylabel('Weight', 'kg')
|
ax1.set_ylabel('Weight', 'kg')
|
||||||
ax1.set_xlim(-10, 310)
|
ax1.set_xlim(-10, 310)
|
||||||
@ -29,10 +29,10 @@ if __name__ == "__main__":
|
|||||||
ax2 = fig.add_subplot(spec[0, 1])
|
ax2 = fig.add_subplot(spec[0, 1])
|
||||||
xx = np.arange(0.0, 350.0, 0.5)
|
xx = np.arange(0.0, 350.0, 0.5)
|
||||||
yy = st.norm.pdf(xx, mu, sigma)
|
yy = st.norm.pdf(xx, mu, sigma)
|
||||||
ax2.plot(yy, xx, color=colors['red'], lw=2)
|
ax2.plot(yy, xx, **lsBm)
|
||||||
bw = 20.0
|
bw = 20.0
|
||||||
h, b = np.histogram(data, np.arange(0, 401, bw))
|
h, b = np.histogram(data, np.arange(0, 401, bw))
|
||||||
ax2.barh(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], height=bar_fac*bw, align='edge')
|
ax2.barh(b[:-1], h/np.sum(h)/(b[1]-b[0]), height=bar_fac*bw, align='edge', **fsC)
|
||||||
ax2.set_xlabel('Pdf', '1/kg')
|
ax2.set_xlabel('Pdf', '1/kg')
|
||||||
ax2.set_xlim(0, 0.012)
|
ax2.set_xlim(0, 0.012)
|
||||||
ax2.set_xticks([0, 0.005, 0.01])
|
ax2.set_xticks([0, 0.005, 0.01])
|
||||||
|
@ -24,32 +24,28 @@ if __name__ == "__main__":
|
|||||||
spec = gridspec.GridSpec(nrows=2, ncols=2, **adjust_fs(fig))
|
spec = gridspec.GridSpec(nrows=2, ncols=2, **adjust_fs(fig))
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[0, 0])
|
ax = fig.add_subplot(spec[0, 0])
|
||||||
ax.plot(indices, x1, c=colors['blue'], lw=1, zorder=10)
|
ax.plot(indices, x1, zorder=10, **lpsAm)
|
||||||
ax.scatter(indices, x1, c=colors['blue'], edgecolor='white', s=50, zorder=20)
|
|
||||||
ax.set_xlabel('Index')
|
ax.set_xlabel('Index')
|
||||||
ax.set_ylabel('Random number')
|
ax.set_ylabel('Random number')
|
||||||
ax.set_xlim(-1.0, n+1.0)
|
ax.set_xlim(-1.0, n+1.0)
|
||||||
ax.set_ylim(-0.05, 1.05)
|
ax.set_ylim(-0.05, 1.05)
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[0, 1])
|
ax = fig.add_subplot(spec[0, 1])
|
||||||
ax.plot(indices, x2, c=colors['blue'], lw=1, zorder=10)
|
ax.plot(indices, x2, zorder=10, **lpsAm)
|
||||||
ax.scatter(indices, x2, c=colors['blue'], edgecolor='white', s=50, zorder=20)
|
|
||||||
ax.set_xlabel('Index')
|
ax.set_xlabel('Index')
|
||||||
ax.set_ylabel('Random number')
|
ax.set_ylabel('Random number')
|
||||||
ax.set_xlim(-1.0, n+1.0)
|
ax.set_xlim(-1.0, n+1.0)
|
||||||
ax.set_ylim(-0.05, 1.05)
|
ax.set_ylim(-0.05, 1.05)
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[1, 1])
|
ax = fig.add_subplot(spec[1, 1])
|
||||||
ax.plot(indices, x3, c=colors['blue'], lw=1, zorder=10)
|
ax.plot(indices, x3, zorder=10, **lpsAm)
|
||||||
ax.scatter(indices, x3, c=colors['blue'], edgecolor='white', s=50, zorder=20)
|
|
||||||
ax.set_xlabel('Index')
|
ax.set_xlabel('Index')
|
||||||
ax.set_ylabel('Random number')
|
ax.set_ylabel('Random number')
|
||||||
ax.set_xlim(-1.0, n+1.0)
|
ax.set_xlim(-1.0, n+1.0)
|
||||||
ax.set_ylim(-0.05, 1.05)
|
ax.set_ylim(-0.05, 1.05)
|
||||||
|
|
||||||
ax = fig.add_subplot(spec[1, 0])
|
ax = fig.add_subplot(spec[1, 0])
|
||||||
ax.plot(lags, corrs, c=colors['red'], lw=1, zorder=10)
|
ax.plot(lags, corrs, zorder=10, **lpsBm)
|
||||||
ax.scatter(lags, corrs, c=colors['red'], edgecolor='white', s=50, zorder=20)
|
|
||||||
ax.set_xlabel('Lag')
|
ax.set_xlabel('Lag')
|
||||||
ax.set_ylabel('Serial correlation')
|
ax.set_ylabel('Serial correlation')
|
||||||
ax.set_xlim(-maxl-0.5, maxl+0.5)
|
ax.set_xlim(-maxl-0.5, maxl+0.5)
|
||||||
|
@ -23,8 +23,8 @@ if __name__ == "__main__":
|
|||||||
fig = plt.figure()
|
fig = plt.figure()
|
||||||
spec = gridspec.GridSpec(nrows=1, ncols=2, **adjust_fs(fig, left=4.5))
|
spec = gridspec.GridSpec(nrows=1, ncols=2, **adjust_fs(fig, left=4.5))
|
||||||
ax1 = fig.add_subplot(spec[0, 0])
|
ax1 = fig.add_subplot(spec[0, 0])
|
||||||
ax1.plot(xx, yy, **ls['A1'])
|
ax1.plot(x, y, **psAm)
|
||||||
ax1.scatter(x, y, c=colors['blue'], edgecolor='white', s=50)
|
ax1.plot(xx, yy, **lsB)
|
||||||
ax1.set_xlabel('Hair deflection', 'nm')
|
ax1.set_xlabel('Hair deflection', 'nm')
|
||||||
ax1.set_ylabel('Conductance', 'nS')
|
ax1.set_ylabel('Conductance', 'nS')
|
||||||
ax1.set_xlim(-20, 20)
|
ax1.set_xlim(-20, 20)
|
||||||
@ -35,10 +35,10 @@ if __name__ == "__main__":
|
|||||||
ax2 = fig.add_subplot(spec[0, 1])
|
ax2 = fig.add_subplot(spec[0, 1])
|
||||||
xg = np.linspace(-3.0, 3.01, 200)
|
xg = np.linspace(-3.0, 3.01, 200)
|
||||||
yg = st.norm.pdf(xg, 0.0, sigma)
|
yg = st.norm.pdf(xg, 0.0, sigma)
|
||||||
ax2.plot(xg, yg, **ls['A1'])
|
ax2.plot(xg, yg, **lsB)
|
||||||
bw = 0.25
|
bw = 0.25
|
||||||
h, b = np.histogram(y-boltzmann(x, x0, k), np.arange(-3.0, 3.01, bw))
|
h, b = np.histogram(y-boltzmann(x, x0, k), np.arange(-3.0, 3.01, bw))
|
||||||
ax2.bar(b[:-1], h/np.sum(h)/(b[1]-b[0]), fc=colors['yellow'], width=bar_fac*bw, align='edge')
|
ax2.bar(b[:-1], h/np.sum(h)/(b[1]-b[0]), width=bar_fac*bw, align='edge', **fsC)
|
||||||
ax2.set_xlabel('Residuals', 'nS')
|
ax2.set_xlabel('Residuals', 'nS')
|
||||||
ax2.set_ylabel('Pdf', '1/nS')
|
ax2.set_ylabel('Pdf', '1/nS')
|
||||||
ax2.set_xlim(-2.5, 2.5)
|
ax2.set_xlim(-2.5, 2.5)
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
rng = np.random.RandomState(981)
|
rng = np.random.RandomState(981)
|
||||||
x = rng.randn( 40, 10 )
|
x = rng.randn( 40, 10 )
|
||||||
|
|
||||||
plt.xkcd()
|
fig, ax = plt.subplots()
|
||||||
fig = plt.figure( figsize=(6,3.4) )
|
|
||||||
ax = fig.add_subplot( 1, 1, 1 )
|
|
||||||
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_xlabel('Experiment')
|
ax.set_xlabel('Experiment')
|
||||||
ax.set_ylabel('x')
|
ax.set_ylabel('x')
|
||||||
ax.set_ylim(-4.0, 4.0)
|
ax.set_ylim(-4.0, 4.0)
|
||||||
@ -40,7 +35,5 @@ ax.annotate('maximum',
|
|||||||
arrowprops=dict(arrowstyle="->", relpos=(1.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(1.0,0.5),
|
||||||
connectionstyle="angle3,angleA=0,angleB=120") )
|
connectionstyle="angle3,angleA=0,angleB=120") )
|
||||||
ax.boxplot(x, whis=100.0)
|
ax.boxplot(x, whis=100.0)
|
||||||
plt.tight_layout()
|
|
||||||
plt.savefig('boxwhisker.pdf')
|
plt.savefig('boxwhisker.pdf')
|
||||||
#plt.show()
|
|
||||||
|
|
||||||
|
@ -1,33 +1,30 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
plt.xkcd()
|
fig = plt.figure(figsize=cm_size(figure_width, 2.0*figure_height))
|
||||||
fig = plt.figure( figsize=(6,4.6) )
|
spec = gridspec.GridSpec(nrows=2, ncols=2, wspace=0.35, hspace=0.5,
|
||||||
|
**adjust_fs(fig, left=5.5, top=0.5, bottom=2.7))
|
||||||
rng = np.random.RandomState(2981)
|
rng = np.random.RandomState(2981)
|
||||||
n = 200
|
n = 200
|
||||||
for k, r in enumerate([ 1.0, 0.6, 0.0, -0.9 ]) :
|
for k, r in enumerate([ 1.0, 0.6, 0.0, -0.9 ]) :
|
||||||
x = rng.randn(n)
|
x = rng.randn(n)
|
||||||
y = r*x + np.sqrt(1.0-r*r)*rng.randn(n)
|
y = r*x + np.sqrt(1.0-r*r)*rng.randn(n)
|
||||||
ax = fig.add_subplot( 2, 2, k+1 )
|
ax = fig.add_subplot(spec[k//2, k%2])
|
||||||
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.text(-2, 2.5, 'r=%.1f' % r)
|
ax.text(-2, 2.5, 'r=%.1f' % r)
|
||||||
if k == 0 :
|
if k == 0 :
|
||||||
ax.text( 2.8, -2, 'positively\ncorrelated', ha='right' )
|
ax.text(2.8, -2.8, 'positively\ncorrelated', ha='right', va='bottom')
|
||||||
elif k == 1 :
|
elif k == 1 :
|
||||||
ax.text( 2.8, -2.5, 'weakly\ncorrelated', ha='right' )
|
ax.text(2.8, -2.8, 'weakly\ncorrelated', ha='right', va='bottom')
|
||||||
elif k == 2 :
|
elif k == 2 :
|
||||||
ax.text( 2.8, -2.5, 'not\ncorrelated', ha='right' )
|
ax.text(2.8, -2.8, 'not\ncorrelated', ha='right', va='bottom')
|
||||||
elif k == 3 :
|
elif k == 3 :
|
||||||
ax.text( -2.5, -2, 'negatively\ncorrelated', ha='left' )
|
ax.text(-2.8, -2.8, 'negatively\ncorrelated', ha='left', va='bottom')
|
||||||
ax.set_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_ylabel('y')
|
ax.set_ylabel('y')
|
||||||
ax.set_xlim(-3.0, 3.0)
|
ax.set_xlim(-3.0, 3.0)
|
||||||
ax.set_ylim(-3.0, 3.0)
|
ax.set_ylim(-3.0, 3.0)
|
||||||
ax.scatter( x[(np.abs(x)<2.8)&(np.abs(y)<2.8)], y[(np.abs(x)<2.8)&(np.abs(y)<2.8)] )
|
ax.plot(x[(np.abs(x)<2.8)&(np.abs(y)<2.8)], y[(np.abs(x)<2.8)&(np.abs(y)<2.8)], **psAm)
|
||||||
|
|
||||||
plt.tight_layout()
|
|
||||||
plt.savefig('correlation.pdf')
|
plt.savefig('correlation.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# data:
|
# data:
|
||||||
rng = np.random.RandomState(981)
|
rng = np.random.RandomState(981)
|
||||||
@ -14,13 +15,7 @@ gauss = np.exp(-0.5*xx*xx)/np.sqrt(2.0*np.pi)
|
|||||||
gausscdf = np.cumsum(gauss)*dx
|
gausscdf = np.cumsum(gauss)*dx
|
||||||
|
|
||||||
# plot:
|
# plot:
|
||||||
plt.xkcd()
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
fig = plt.figure( figsize=(6, 2.4) )
|
|
||||||
ax = fig.add_subplot(1, 1, 1)
|
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_xlim(-3.2, 3.2)
|
ax.set_xlim(-3.2, 3.2)
|
||||||
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
@ -29,24 +24,22 @@ ax.set_ylim(-0.05, 1.05)
|
|||||||
ax.set_yticks(np.arange(0.0, 1.1, 0.2))
|
ax.set_yticks(np.arange(0.0, 1.1, 0.2))
|
||||||
|
|
||||||
med = xs[cdf>=0.5][0]
|
med = xs[cdf>=0.5][0]
|
||||||
ax.plot([-3.2, med, med], [0.5, 0.5, 0.0], 'k', lw=1, zorder=-5)
|
ax.plot([-3.2, med, med], [0.5, 0.5, 0.0], zorder=-5, **lsSpine)
|
||||||
ax.text(-2.8, 0.55, 'F=0.5')
|
ax.text(-2.8, 0.55, 'F=0.5')
|
||||||
ax.text(0.15, 0.25, 'median at %.2f' % med)
|
ax.text(0.15, 0.25, 'median at %.2f' % med)
|
||||||
|
|
||||||
q3 = xs[cdf>=0.75][0]
|
q3 = xs[cdf>=0.75][0]
|
||||||
ax.plot([-3.2, q3, q3], [0.75, 0.75, 0.0], 'k', lw=1, zorder=-5)
|
ax.plot([-3.2, q3, q3], [0.75, 0.75, 0.0], zorder=-5, **lsSpine)
|
||||||
ax.text(-2.8, 0.8, 'F=0.75')
|
ax.text(-2.8, 0.8, 'F=0.75')
|
||||||
ax.text(0.8, 0.5, '3. quartile at %.2f' % q3)
|
ax.text(0.8, 0.5, '3. quartile at %.2f' % q3)
|
||||||
|
|
||||||
p = cdf[xs>=-1.0][0]
|
p = cdf[xs>=-1.0][0]
|
||||||
ax.plot([-3.2, -1.0, -1.0], [p, p, 0.0], 'k', lw=1, zorder=-5)
|
ax.plot([-3.2, -1.0, -1.0], [p, p, 0.0], zorder=-5, **lsSpine)
|
||||||
ax.text(-2.8, 0.2, 'F=%.2f' % p)
|
ax.text(-2.8, 0.2, 'F=%.2f' % p)
|
||||||
ax.text(-0.9, 0.05, '-1')
|
ax.text(-0.9, 0.05, '-1')
|
||||||
|
|
||||||
ax.plot(xx, gausscdf, '-', color='#0000ff', lw=2, zorder=-1)
|
ax.plot(xx, gausscdf, zorder=-1, **lsAm)
|
||||||
ax.plot(xs, cdf, '-', color='#cc0000', lw=4, zorder=-1)
|
ax.plot(xs, cdf, zorder=-1, **lsB)
|
||||||
ax.plot([-3.2, 3.2], [1.0, 1.0], '--', color='k', lw=2, zorder=-10)
|
ax.plot([-3.2, 3.2], [1.0, 1.0], zorder=-10, **lsGrid)
|
||||||
|
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.35, hspace=0.3)
|
|
||||||
fig.savefig('cumulative.pdf')
|
fig.savefig('cumulative.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# roll the die:
|
# roll the die:
|
||||||
rng = np.random.RandomState(57281)
|
rng = np.random.RandomState(57281)
|
||||||
@ -7,33 +8,23 @@ x1 = rng.random_integers( 1, 6, 100 )
|
|||||||
x2 = rng.random_integers(1, 6, 500)
|
x2 = rng.random_integers(1, 6, 500)
|
||||||
bins = np.arange(0.5, 7, 1.0)
|
bins = np.arange(0.5, 7, 1.0)
|
||||||
|
|
||||||
plt.xkcd()
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
|
fig.subplots_adjust(**adjust_fs(bottom=2.7, top=0.1))
|
||||||
|
ax1.set_xlim(0, 7)
|
||||||
|
ax1.set_xticks(range(1, 7))
|
||||||
|
ax1.set_xlabel('x')
|
||||||
|
ax1.set_ylim(0, 98)
|
||||||
|
ax1.set_ylabel('Frequency')
|
||||||
|
fs = fsC
|
||||||
|
fs['color'] = [fsC['facecolor'], fsE['facecolor']]
|
||||||
|
del fs['facecolor']
|
||||||
|
ax1.hist([x2, x1], bins, **fs)
|
||||||
|
|
||||||
fig = plt.figure( figsize=(6,3) )
|
ax2.set_xlim(0, 7)
|
||||||
ax = fig.add_subplot( 1, 2, 1 )
|
ax2.set_xticks(range(1, 7))
|
||||||
ax.spines['right'].set_visible(False)
|
ax2.set_xlabel('x')
|
||||||
ax.spines['top'].set_visible(False)
|
ax2.set_ylim(0, 0.23)
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax2.set_ylabel('Probability')
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=-10, **lsAm)
|
||||||
ax.set_xlim(0, 7)
|
ax2.hist([x2, x1], bins, normed=True, zorder=-5, **fs)
|
||||||
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' ])
|
|
||||||
|
|
||||||
ax = fig.add_subplot( 1, 2, 2 )
|
|
||||||
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.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], '-b', lw=2, zorder=1)
|
|
||||||
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ], zorder=10)
|
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.4, hspace=0.0)
|
|
||||||
fig.savefig('diehistograms.pdf')
|
fig.savefig('diehistograms.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,33 +1,24 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
from scipy.stats import gaussian_kde
|
from scipy.stats import gaussian_kde
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
#rng = np.random.RandomState(981)
|
#rng = np.random.RandomState(981)
|
||||||
#data = rng.randn(40, 1) + 4.0
|
#data = rng.randn(40, 1) + 4.0
|
||||||
rng = np.random.RandomState(1981)
|
rng = np.random.RandomState(1981)
|
||||||
data = rng.gamma(1.0, 1.5, 40) + 1.0
|
data = rng.gamma(1.0, 1.5, 40) + 1.0
|
||||||
data = data[data<7.5]
|
data = data[data<7.5]
|
||||||
xpos = 0.08
|
|
||||||
ypos = 0.15
|
|
||||||
width = 0.65
|
|
||||||
height = 0.8
|
|
||||||
barwidth = 0.8
|
barwidth = 0.8
|
||||||
scatterpos = 1.0
|
scatterpos = 1.0
|
||||||
barpos = 2.5
|
barpos = 2.5
|
||||||
boxpos = 4.0
|
boxpos = 4.0
|
||||||
|
|
||||||
plt.xkcd()
|
fig = plt.figure(figsize=cm_size(figure_width, 1.1*figure_height))
|
||||||
fig = plt.figure( figsize=(6,3.4) )
|
spec = gridspec.GridSpec(nrows=1, ncols=2, width_ratios=[3, 1], wspace=0.1,
|
||||||
|
**adjust_fs(fig, left=4.0))
|
||||||
|
|
||||||
ax = fig.add_axes([xpos, ypos, width, height])
|
ax = fig.add_subplot(spec[0, 0])
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
#ax.spines['left'].set_visible(False)
|
|
||||||
#ax.spines['bottom'].set_visible(False)
|
|
||||||
#ax.xaxis.set_ticks_position('none')
|
|
||||||
#ax.yaxis.set_ticks_position('none')
|
|
||||||
#ax.set_xticklabels([])
|
|
||||||
#ax.set_yticklabels([])
|
|
||||||
wh = ax.boxplot( data, positions=[boxpos], widths=[barwidth], whis=100.0, patch_artist=True)
|
wh = ax.boxplot( data, positions=[boxpos], widths=[barwidth], whis=100.0, patch_artist=True)
|
||||||
wh['medians'][0].set_linewidth(4)
|
wh['medians'][0].set_linewidth(4)
|
||||||
wh['whiskers'][0].set_linewidth(2)
|
wh['whiskers'][0].set_linewidth(2)
|
||||||
@ -49,7 +40,7 @@ ax.annotate('maximum',
|
|||||||
connectionstyle="angle3,angleA=0,angleB=120") )
|
connectionstyle="angle3,angleA=0,angleB=120") )
|
||||||
ax.annotate('3. quartile',
|
ax.annotate('3. quartile',
|
||||||
xy=(boxpos-0.3*barwidth, 3.7), xycoords='data',
|
xy=(boxpos-0.3*barwidth, 3.7), xycoords='data',
|
||||||
xytext=(boxpos-1.3*barwidth, 5.5), textcoords='data', ha='left',
|
xytext=(boxpos-0.1*barwidth, 5.5), textcoords='data', ha='right',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.4,0.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.4,0.0),
|
||||||
connectionstyle="angle3,angleA=0,angleB=120") )
|
connectionstyle="angle3,angleA=0,angleB=120") )
|
||||||
ax.annotate('median',
|
ax.annotate('median',
|
||||||
@ -57,34 +48,28 @@ ax.annotate('median',
|
|||||||
xytext=(boxpos+0.1*barwidth, 4.2), textcoords='data', ha='left',
|
xytext=(boxpos+0.1*barwidth, 4.2), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.8,0.0),
|
||||||
connectionstyle="angle3,angleA=-60,angleB=20") )
|
connectionstyle="angle3,angleA=-60,angleB=20") )
|
||||||
|
|
||||||
ax = fig.add_axes([xpos, ypos, width, height])
|
|
||||||
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_xticklabels([])
|
ax.set_xticklabels([])
|
||||||
|
|
||||||
|
ax = fig.add_subplot(spec[0, 0])
|
||||||
ax.set_xlim(0.0, 4.8)
|
ax.set_xlim(0.0, 4.8)
|
||||||
|
ax.set_xticks([scatterpos, barpos, boxpos])
|
||||||
|
ax.set_xticklabels(['(1) data', '(2) bar\n plot', '(3) box-\nwhisker'], fontsize='medium')
|
||||||
ax.set_ylabel('x')
|
ax.set_ylabel('x')
|
||||||
ax.set_ylim( 0.0, 8.0)
|
ax.set_ylim( 0.0, 8.0)
|
||||||
|
|
||||||
ax.set_xticks([scatterpos, barpos, boxpos])
|
|
||||||
ax.set_xticklabels(['(1) data', '(2) bar\n plot', '(3) box-\nwhisker'])
|
|
||||||
|
|
||||||
# scatter data points according to their density:
|
# scatter data points according to their density:
|
||||||
kernel = gaussian_kde(data)
|
kernel = gaussian_kde(data)
|
||||||
x = kernel(data)
|
x = kernel(data)
|
||||||
x /= np.max(x)
|
x /= np.max(x)
|
||||||
ax.scatter(scatterpos+barwidth*x*(rng.rand(len(data))-0.5), data, s=50)
|
ax.plot(scatterpos+barwidth*x*(rng.rand(len(data))-0.5), data, **psA)
|
||||||
|
|
||||||
barmean = np.mean(data)
|
barmean = np.mean(data)
|
||||||
barstd = np.std(data)
|
barstd = np.std(data)
|
||||||
ew = 0.2
|
ew = 0.2
|
||||||
ax.bar([barpos-0.5*barwidth], [barmean], barwidth, color='#FFCC00')
|
ax.bar([barpos-0.5*barwidth], [barmean], barwidth, **fsC)
|
||||||
eargs = {'color': 'k', 'lw': 2}
|
ax.plot([barpos, barpos], [barmean-barstd, barmean+barstd], **lsMarker)
|
||||||
ax.plot([barpos, barpos], [barmean-barstd, barmean+barstd], **eargs)
|
ax.plot([barpos-0.5*ew, barpos+0.5*ew], [barmean-barstd, barmean-barstd], **lsMarker)
|
||||||
ax.plot([barpos-0.5*ew, barpos+0.5*ew], [barmean-barstd, barmean-barstd], **eargs)
|
ax.plot([barpos-0.5*ew, barpos+0.5*ew], [barmean+barstd, barmean+barstd], **lsMarker)
|
||||||
ax.plot([barpos-0.5*ew, barpos+0.5*ew], [barmean+barstd, barmean+barstd], **eargs)
|
|
||||||
ax.annotate('mean',
|
ax.annotate('mean',
|
||||||
xy=(barpos-0.4*barwidth, 2.7), xycoords='data',
|
xy=(barpos-0.4*barwidth, 2.7), xycoords='data',
|
||||||
xytext=(barpos-1*barwidth, 5.5), textcoords='data', ha='left',
|
xytext=(barpos-1*barwidth, 5.5), textcoords='data', ha='left',
|
||||||
@ -96,20 +81,15 @@ ax.annotate('mean plus\nstd. dev.',
|
|||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
||||||
connectionstyle="angle3,angleA=-60,angleB=80") )
|
connectionstyle="angle3,angleA=-60,angleB=80") )
|
||||||
|
|
||||||
ax = fig.add_axes([xpos+width+0.03, ypos, 0.98-(xpos+width+0.03), height])
|
ax = fig.add_subplot(spec[0, 1])
|
||||||
ax.spines['right'].set_visible(False)
|
|
||||||
ax.spines['top'].set_visible(False)
|
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
|
||||||
ax.yaxis.set_ticks_position('left')
|
|
||||||
ax.set_yticklabels([])
|
ax.set_yticklabels([])
|
||||||
ax.set_ylim( 0.0, 8.0)
|
ax.set_ylim( 0.0, 8.0)
|
||||||
ax.set_xticks(np.arange(0.0, 0.4, 0.1))
|
ax.set_xticks(np.arange(0.0, 0.4, 0.1))
|
||||||
ax.set_xlabel('(4) p(x)')
|
ax.set_xlabel('(4) pdf')
|
||||||
bw = 0.75
|
bw = 0.75
|
||||||
bins = np.arange(0, 8.0+bw, bw)
|
bins = np.arange(0, 8.0+bw, bw)
|
||||||
h, b = np.histogram(data, bins)
|
h, b = np.histogram(data, bins)
|
||||||
ax.barh(b[:-1], h/bw/np.sum(h), bw, color='#CC0000')
|
ax.barh(b[:-1], h/bw/np.sum(h), bw, **fsB)
|
||||||
|
|
||||||
plt.savefig('displayunivariatedata.pdf')
|
plt.savefig('displayunivariatedata.pdf')
|
||||||
#plt.show()
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# normal distribution:
|
# normal distribution:
|
||||||
rng = np.random.RandomState(6281)
|
rng = np.random.RandomState(6281)
|
||||||
@ -30,15 +32,11 @@ def kerneldensity(data, xmin, xmax, sigma=1.0) :
|
|||||||
kd /= len(data)
|
kd /= len(data)
|
||||||
return kd, x
|
return kd, x
|
||||||
|
|
||||||
|
fig = plt.figure()
|
||||||
|
spec = gridspec.GridSpec(nrows=2, ncols=2, wspace=0.35, hspace=0.3,
|
||||||
|
**adjust_fs(fig, left=5.5, top=0.2, bottom=2.7))
|
||||||
|
|
||||||
plt.xkcd()
|
ax = fig.add_subplot(spec[0, 0])
|
||||||
|
|
||||||
fig = plt.figure( figsize=(6,3) )
|
|
||||||
ax = fig.add_subplot(2, 2, 1)
|
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_xlim(-3.2, 3.2)
|
ax.set_xlim(-3.2, 3.2)
|
||||||
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
@ -46,13 +44,9 @@ ax.set_ylabel( 'p(x)' )
|
|||||||
ax.set_ylim(0.0, 0.49)
|
ax.set_ylim(0.0, 0.49)
|
||||||
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
||||||
ax.hist(r, np.arange(-4.1, 4, 0.4), normed=True, color='#FFCC00', zorder=-5)
|
ax.hist(r, np.arange(-4.1, 4, 0.4), normed=True, zorder=-5, **fsC)
|
||||||
|
|
||||||
ax = fig.add_subplot(2, 2, 3)
|
ax = fig.add_subplot(spec[1, 0])
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_xlim(-3.2, 3.2)
|
ax.set_xlim(-3.2, 3.2)
|
||||||
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
@ -60,24 +54,18 @@ ax.set_ylabel( 'p(x)' )
|
|||||||
ax.set_ylim(0.0, 0.49)
|
ax.set_ylim(0.0, 0.49)
|
||||||
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
#ax.plot(x, g, '-b', lw=2, zorder=-1)
|
||||||
ax.hist(r, np.arange(-4.3, 4, 0.4), normed=True, color='#FFCC00', zorder=-5)
|
ax.hist(r, np.arange(-4.3, 4, 0.4), normed=True, zorder=-5, **fsC)
|
||||||
|
|
||||||
ax = fig.add_subplot(1, 2, 2)
|
ax = fig.add_subplot(spec[:, 1])
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_xlim(-3.2, 3.2)
|
ax.set_xlim(-3.2, 3.2)
|
||||||
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
ax.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
ax.set_ylabel( 'Probab. density p(x)' )
|
ax.set_ylabel('Prob. density p(x)')
|
||||||
ax.set_ylim(0.0, 0.49)
|
ax.set_ylim(0.0, 0.49)
|
||||||
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
ax.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
kd, xx = kerneldensity(r, -3.2, 3.2, 0.2)
|
kd, xx = kerneldensity(r, -3.2, 3.2, 0.2)
|
||||||
ax.fill_between(xx, 0.0, kd, color='#FF9900', zorder=-5)
|
ax.fill_between(xx, 0.0, kd, zorder=-5, **fsDs)
|
||||||
ax.plot(xx, kd, '-', lw=3, color='#CC0000', zorder=-1)
|
ax.plot(xx, kd, '-', zorder=-1, **lsB)
|
||||||
|
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.35, hspace=0.3)
|
|
||||||
fig.savefig('kerneldensity.pdf')
|
fig.savefig('kerneldensity.pdf')
|
||||||
#plt.show()
|
|
||||||
|
|
||||||
|
@ -1,78 +1,66 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import scipy.stats as st
|
import scipy.stats as st
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# normal distribution:
|
# normal distribution:
|
||||||
x = np.arange(-3.0, 3.0, 0.01)
|
x = np.arange(-3.0, 3.0, 0.01)
|
||||||
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
||||||
|
|
||||||
plt.xkcd()
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
fig = plt.figure( figsize=(6, 2.8) )
|
fig.subplots_adjust(**adjust_fs(bottom=2.7, top=0.1))
|
||||||
ax = fig.add_subplot(1, 2, 1)
|
ax1.set_xlabel('x')
|
||||||
ax.spines['right'].set_visible(False)
|
ax1.set_ylabel('Prob. density p(x)')
|
||||||
ax.spines['top'].set_visible(False)
|
ax1.set_ylim(0.0, 0.46)
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax1.set_yticks(np.arange(0.0, 0.45, 0.1))
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax1.text(-1.0, 0.06, '50%', ha='center')
|
||||||
ax.set_xlabel( 'x' )
|
ax1.text(+1.0, 0.06, '50%', ha='center')
|
||||||
ax.set_ylabel( 'Prob. density p(x)' )
|
ax1.annotate('Median\n= mean',
|
||||||
ax.set_ylim( 0.0, 0.46 )
|
|
||||||
ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
|
|
||||||
ax.text(-1.0, 0.06, '50%', ha='center' )
|
|
||||||
ax.text(+1.0, 0.06, '50%', ha='center' )
|
|
||||||
ax.annotate('Median\n= mean',
|
|
||||||
xy=(0.1, 0.3), xycoords='data',
|
xy=(0.1, 0.3), xycoords='data',
|
||||||
xytext=(1.2, 0.35), textcoords='data', ha='left',
|
xytext=(1.2, 0.35), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
||||||
connectionstyle="angle3,angleA=10,angleB=40"))
|
connectionstyle="angle3,angleA=10,angleB=40"))
|
||||||
ax.annotate('Mode',
|
ax1.annotate('Mode',
|
||||||
xy=(-0.1, 0.4), xycoords='data',
|
xy=(-0.1, 0.4), xycoords='data',
|
||||||
xytext=(-2.5, 0.43), textcoords='data', ha='left',
|
xytext=(-2.5, 0.43), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.2),
|
||||||
connectionstyle="angle3,angleA=10,angleB=120"))
|
connectionstyle="angle3,angleA=10,angleB=120"))
|
||||||
ax.fill_between( x[x<0], 0.0, g[x<0], color='#ffcc00' )
|
ax1.fill_between(x[x<0], 0.0, g[x<0], **fsCs)
|
||||||
ax.fill_between( x[x>0], 0.0, g[x>0], color='#99ff00' )
|
ax1.fill_between(x[x>0], 0.0, g[x>0], **fsFs)
|
||||||
ax.plot(x, g, 'b', lw=4)
|
ax1.plot(x, g, **lsA)
|
||||||
ax.plot([0.0, 0.0], [0.0, 0.45], 'k', lw=2 )
|
ax1.plot([0.0, 0.0], [0.0, 0.45], **lsMarker)
|
||||||
|
|
||||||
# normal distribution:
|
# gamma distribution:
|
||||||
x = np.arange(0.0, 6.0, 0.01)
|
x = np.arange(0.0, 6.0, 0.01)
|
||||||
shape = 2.0
|
shape = 2.0
|
||||||
g = st.gamma.pdf(x, shape)
|
g = st.gamma.pdf(x, shape)
|
||||||
m = st.gamma.median(shape)
|
m = st.gamma.median(shape)
|
||||||
gm = st.gamma.mean(shape)
|
gm = st.gamma.mean(shape)
|
||||||
ax = fig.add_subplot(1, 2, 2)
|
ax2.set_xlabel('x')
|
||||||
ax.spines['right'].set_visible(False)
|
ax2.set_ylabel('Prob. density p(x)')
|
||||||
ax.spines['top'].set_visible(False)
|
ax2.set_ylim(0.0, 0.46)
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax2.set_yticks(np.arange(0.0, 0.45, 0.1))
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax2.text(m-0.8, 0.06, '50%', ha='center')
|
||||||
ax.set_xlabel( 'x' )
|
ax2.text(m+1.2, 0.06, '50%', ha='center')
|
||||||
ax.set_ylabel( 'Prob. density p(x)' )
|
ax2.annotate('Median',
|
||||||
ax.set_ylim( 0.0, 0.46 )
|
|
||||||
ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
|
|
||||||
ax.text(m-0.8, 0.06, '50%', ha='center' )
|
|
||||||
ax.text(m+1.2, 0.06, '50%', ha='center' )
|
|
||||||
ax.annotate('Median',
|
|
||||||
xy=(m+0.1, 0.2), xycoords='data',
|
xy=(m+0.1, 0.2), xycoords='data',
|
||||||
xytext=(m+1.6, 0.25), textcoords='data', ha='left',
|
xytext=(m+1.6, 0.25), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=30,angleB=70"))
|
connectionstyle="angle3,angleA=30,angleB=70"))
|
||||||
ax.annotate('Mean',
|
ax2.annotate('Mean',
|
||||||
xy=(gm, 0.01), xycoords='data',
|
xy=(gm, 0.01), xycoords='data',
|
||||||
xytext=(gm+1.8, 0.15), textcoords='data', ha='left',
|
xytext=(gm+1.8, 0.15), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=0,angleB=90"))
|
connectionstyle="angle3,angleA=0,angleB=90"))
|
||||||
ax.annotate('Mode',
|
ax2.annotate('Mode',
|
||||||
xy=(1.0, 0.38), xycoords='data',
|
xy=(1.0, 0.38), xycoords='data',
|
||||||
xytext=(1.8, 0.42), textcoords='data', ha='left',
|
xytext=(1.8, 0.42), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=0,angleB=70"))
|
connectionstyle="angle3,angleA=0,angleB=70"))
|
||||||
ax.fill_between( x[x<m], 0.0, g[x<m], color='#ffcc00' )
|
ax2.fill_between(x[x<m], 0.0, g[x<m], **fsCs)
|
||||||
ax.fill_between( x[x>m], 0.0, g[x>m], color='#99ff00' )
|
ax2.fill_between(x[x>m], 0.0, g[x>m], **fsFs)
|
||||||
ax.plot(x, g, 'b', lw=4)
|
ax2.plot(x, g, **lsA)
|
||||||
ax.plot([m, m], [0.0, 0.38], 'k', lw=2 )
|
ax2.plot([m, m], [0.0, 0.38], **lsMarker)
|
||||||
#ax.plot([gm, gm], [0.0, 0.42], 'k', lw=2 )
|
#ax2.plot([gm, gm], [0.0, 0.38], **lsMarker)
|
||||||
|
|
||||||
#plt.tight_layout()
|
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.4, hspace=0.0)
|
|
||||||
fig.savefig('median.pdf')
|
fig.savefig('median.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,42 +1,35 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
import matplotlib.gridspec as gridspec
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
|
fig.subplots_adjust(wspace=0.35, hspace=0.5,
|
||||||
|
**adjust_fs(fig, left=4, top=0.5, bottom=2.7))
|
||||||
|
|
||||||
plt.xkcd()
|
|
||||||
fig = plt.figure( figsize=(6,2.2) )
|
|
||||||
n = 200
|
n = 200
|
||||||
x = np.random.randn( n )
|
rng = np.random.RandomState(3981)
|
||||||
y = np.random.randn( n )
|
x = rng.randn(n)
|
||||||
|
y = rng.randn(n)
|
||||||
|
|
||||||
z = x*x+0.2*y
|
z = x*x+0.2*y
|
||||||
r =np.corrcoef(x,z)[0,1]
|
r =np.corrcoef(x,z)[0,1]
|
||||||
ax = fig.add_subplot( 1, 2, 1 )
|
ax1.text(0, 4.0, 'r=%.1f' % r, ha='center')
|
||||||
ax.spines['right'].set_visible(False)
|
ax1.text(0, 5.6, r'$y = x^2+\xi/5$', ha='center')
|
||||||
ax.spines['top'].set_visible(False)
|
ax1.set_xlabel('x')
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax1.set_ylabel('y')
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax1.set_xlim(-3.0, 3.0)
|
||||||
ax.text( 0, 4.0, 'r=%.1f' % r, ha='center' )
|
ax1.set_ylim(-0.5, 6.0)
|
||||||
ax.text( 0, 6, r'$y = x^2+\xi/5$', ha='center' )
|
ax1.plot(x, z, **psAm)
|
||||||
ax.set_xlabel('x')
|
|
||||||
ax.set_ylabel('y')
|
|
||||||
ax.set_xlim( -3.0, 3.0)
|
|
||||||
ax.set_ylim( -0.5, 6.0)
|
|
||||||
ax.scatter( x, z )
|
|
||||||
|
|
||||||
z = 0.5*x*y
|
z = 0.5*x*y
|
||||||
r =np.corrcoef(x,z)[0,1]
|
r =np.corrcoef(x,z)[0,1]
|
||||||
ax = fig.add_subplot( 1, 2, 2 )
|
ax2.text(0, 1.5, 'r=%.1f' % r, ha='center')
|
||||||
ax.spines['right'].set_visible(False)
|
ax2.text(0, 2.8, r'$y = x \cdot \xi/2$', ha='center')
|
||||||
ax.spines['top'].set_visible(False)
|
ax2.set_xlabel('x')
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax2.set_ylabel('y')
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax2.set_xlim(-3.0, 3.0)
|
||||||
ax.text( 0, 1.5, 'r=%.1f' % r, ha='center' )
|
ax2.set_ylim(-3.0, 3.0)
|
||||||
ax.text( 0, 3, r'$y = x \cdot \xi/2$', ha='center' )
|
ax2.plot(x, z, **psAm)
|
||||||
ax.set_xlabel('x')
|
|
||||||
ax.set_ylabel('y')
|
|
||||||
ax.set_xlim( -3.0, 3.0)
|
|
||||||
ax.set_ylim( -3.0, 3.0)
|
|
||||||
ax.scatter( x, z )
|
|
||||||
|
|
||||||
plt.tight_layout()
|
|
||||||
plt.savefig('nonlincorrelation.pdf')
|
plt.savefig('nonlincorrelation.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# normal distribution:
|
# normal distribution:
|
||||||
rng = np.random.RandomState(6281)
|
rng = np.random.RandomState(6281)
|
||||||
@ -7,38 +8,24 @@ x = np.arange( -4.0, 4.0, 0.01 )
|
|||||||
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
||||||
r = rng.randn(100)
|
r = rng.randn(100)
|
||||||
|
|
||||||
plt.xkcd()
|
fig, (ax1, ax2) = plt.subplots(1, 2)
|
||||||
|
ax1.set_xlabel('x')
|
||||||
|
ax1.set_xlim(-3.2, 3.2)
|
||||||
|
ax1.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
|
ax1.set_ylabel('Frequency')
|
||||||
|
ax1.set_yticks(np.arange(0.0, 41.0, 10.0))
|
||||||
|
ax1.hist(r, 5, zorder=-10, **fsB)
|
||||||
|
ax1.hist(r, 20, zorder=-5, **fsC)
|
||||||
|
|
||||||
fig = plt.figure( figsize=(6,3) )
|
ax2.set_xlabel('x')
|
||||||
ax = fig.add_subplot( 1, 2, 1 )
|
ax2.set_xlim(-3.2, 3.2)
|
||||||
ax.spines['right'].set_visible(False)
|
ax2.set_xticks(np.arange(-3.0, 3.1, 1.0))
|
||||||
ax.spines['top'].set_visible(False)
|
ax2.set_ylabel('Probab. density p(x)')
|
||||||
ax.yaxis.set_ticks_position('left')
|
ax2.set_ylim(0.0, 0.44)
|
||||||
ax.xaxis.set_ticks_position('bottom')
|
ax2.set_yticks(np.arange(0.0, 0.41, 0.1))
|
||||||
ax.set_xlabel( 'x' )
|
ax2.plot(x, g, zorder=-1, **lsA)
|
||||||
ax.set_xlim(-3.2, 3.2)
|
ax2.hist(r, 5, normed=True, zorder=-10, **fsB)
|
||||||
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
|
ax2.hist(r, 20, normed=True, zorder=-5, **fsC)
|
||||||
ax.set_ylabel( 'Frequency' )
|
|
||||||
ax.set_yticks( np.arange( 0.0, 41.0, 10.0 ) )
|
|
||||||
ax.hist(r, 5, color='#CC0000')
|
|
||||||
ax.hist(r, 20, color='#FFCC00')
|
|
||||||
|
|
||||||
ax = fig.add_subplot( 1, 2, 2 )
|
|
||||||
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_xlabel( 'x' )
|
|
||||||
ax.set_xlim(-3.2, 3.2)
|
|
||||||
ax.set_xticks( np.arange( -3.0, 3.1, 1.0 ) )
|
|
||||||
ax.set_ylabel( 'Probab. density p(x)' )
|
|
||||||
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.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.4, hspace=0.0)
|
|
||||||
fig.savefig('pdfhistogram.pdf')
|
fig.savefig('pdfhistogram.pdf')
|
||||||
#plt.show()
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# normal distribution:
|
# normal distribution:
|
||||||
x = np.arange(-3.0, 5.0, 0.01)
|
x = np.arange(-3.0, 5.0, 0.01)
|
||||||
@ -7,13 +8,7 @@ g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
|||||||
x1=0.0
|
x1=0.0
|
||||||
x2=1.0
|
x2=1.0
|
||||||
|
|
||||||
plt.xkcd()
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.2*figure_height))
|
||||||
fig = plt.figure( figsize=(6,3.4) )
|
|
||||||
ax = fig.add_subplot( 1, 1, 1 )
|
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_ylabel('Probability density p(x)')
|
ax.set_ylabel('Probability density p(x)')
|
||||||
ax.set_ylim(0.0, 0.46)
|
ax.set_ylim(0.0, 0.46)
|
||||||
@ -24,13 +19,10 @@ ax.annotate('Gaussian',
|
|||||||
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
arrowprops=dict(arrowstyle="->", relpos=(0.5,0.0),
|
||||||
connectionstyle="angle3,angleA=10,angleB=110"))
|
connectionstyle="angle3,angleA=10,angleB=110"))
|
||||||
ax.annotate('$P(0<x<1) = \int_0^1 p(x) \, dx$',
|
ax.annotate('$P(0<x<1) = \int_0^1 p(x) \, dx$',
|
||||||
xy=(0.6, 0.28), xycoords='data',
|
xy=(0.5, 0.24), xycoords='data',
|
||||||
xytext=(1.2, 0.4), textcoords='data', ha='left',
|
xytext=(1.2, 0.4), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=10,angleB=80"))
|
connectionstyle="angle3,angleA=10,angleB=80"))
|
||||||
ax.fill_between( x[(x>x1)&(x<x2)], 0.0, g[(x>x1)&(x<x2)], color='#cc0000' )
|
ax.fill_between(x[(x>x1)&(x<x2)], 0.0, g[(x>x1)&(x<x2)], **fsBs)
|
||||||
ax.plot(x,g, 'b', lw=4)
|
ax.plot(x,g, **lsA)
|
||||||
#plt.tight_layout()
|
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.4, hspace=0.0)
|
|
||||||
fig.savefig('pdfprobabilities.pdf')
|
fig.savefig('pdfprobabilities.pdf')
|
||||||
#plt.show()
|
|
||||||
|
@ -1,18 +1,14 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
from plotstyle import *
|
||||||
|
|
||||||
# normal distribution:
|
# normal distribution:
|
||||||
x = np.arange( -4.0, 4.0, 0.01 )
|
x = np.arange( -4.0, 4.0, 0.01 )
|
||||||
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
g = np.exp(-0.5*x*x)/np.sqrt(2.0*np.pi)
|
||||||
q = [ -0.67488, 0.0, 0.67488 ]
|
q = [ -0.67488, 0.0, 0.67488 ]
|
||||||
|
|
||||||
plt.xkcd()
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.0*figure_height))
|
||||||
fig = plt.figure( figsize=(6,3.2) )
|
fig.subplots_adjust(**adjust_fs(bottom=2.7, top=0.1))
|
||||||
ax = fig.add_subplot( 1, 1, 1 )
|
|
||||||
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_xlabel('x')
|
ax.set_xlabel('x')
|
||||||
ax.set_ylabel('Probability density p(x)')
|
ax.set_ylabel('Probability density p(x)')
|
||||||
ax.set_ylim(0.0, 0.46)
|
ax.set_ylim(0.0, 0.46)
|
||||||
@ -36,15 +32,12 @@ ax.annotate('Median',
|
|||||||
xytext=(1.6, 0.35), textcoords='data', ha='left',
|
xytext=(1.6, 0.35), textcoords='data', ha='left',
|
||||||
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
arrowprops=dict(arrowstyle="->", relpos=(0.0,0.5),
|
||||||
connectionstyle="angle3,angleA=10,angleB=40") )
|
connectionstyle="angle3,angleA=10,angleB=40") )
|
||||||
ax.fill_between( x[x<q[0]], 0.0, g[x<q[0]], color='#ffcc00' )
|
ax.fill_between( x[x<q[0]], 0.0, g[x<q[0]], **fsCs)
|
||||||
ax.fill_between( x[(x>q[0])&(x<q[1])], 0.0, g[(x>q[0])&(x<q[1])], color='#ff0000' )
|
ax.fill_between( x[(x>q[0])&(x<q[1])], 0.0, g[(x>q[0])&(x<q[1])], **fsBs)
|
||||||
ax.fill_between( x[(x>q[1])&(x<q[2])], 0.0, g[(x>q[1])&(x<q[2])], color='#ff9900' )
|
ax.fill_between( x[(x>q[1])&(x<q[2])], 0.0, g[(x>q[1])&(x<q[2])], **fsDs)
|
||||||
ax.fill_between( x[x>q[2]], 0.0, g[x>q[2]], color='#ffff66' )
|
ax.fill_between( x[x>q[2]], 0.0, g[x>q[2]], **fsEs)
|
||||||
ax.plot(x,g, 'b', lw=4)
|
ax.plot(x,g, **lsA)
|
||||||
ax.plot([0.0, 0.0], [0.0, 0.45], 'k', lw=2 )
|
ax.plot([0.0, 0.0], [0.0, 0.45], **lsMarker)
|
||||||
ax.plot([q[0], q[0]], [0.0, 0.4], 'k', lw=2 )
|
ax.plot([q[0], q[0]], [0.0, 0.4], **lsMarker)
|
||||||
ax.plot([q[2], q[2]], [0.0, 0.4], 'k', lw=2 )
|
ax.plot([q[2], q[2]], [0.0, 0.4], **lsMarker)
|
||||||
plt.subplots_adjust(left=0.1, right=0.98, bottom=0.15, top=0.98, wspace=0.4, hspace=0.0)
|
|
||||||
#plt.tight_layout()
|
|
||||||
fig.savefig( 'quartile.pdf' )
|
fig.savefig( 'quartile.pdf' )
|
||||||
#plt.show()
|
|
||||||
|
@ -115,17 +115,9 @@ function \mcode{median()} computes the median.
|
|||||||
writing reliable code!
|
writing reliable code!
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
\begin{figure}[t]
|
|
||||||
\includegraphics[width=1\textwidth]{quartile}
|
|
||||||
\titlecaption{\label{quartilefig} Median and quartiles of a normal
|
|
||||||
distribution.}{ The interquartile range between the first and the
|
|
||||||
third quartile contains 50\,\% of the data and contains the
|
|
||||||
median.}
|
|
||||||
\end{figure}
|
|
||||||
|
|
||||||
The distribution of data can be further characterized by the position
|
The distribution of data can be further characterized by the position
|
||||||
of its \entermde[quartile]{Quartil}{quartiles}. Neighboring quartiles are
|
of its \entermde[quartile]{Quartil}{quartiles}. Neighboring quartiles are
|
||||||
separated by 25\,\% of the data (\figref{quartilefig}).
|
separated by 25\,\% of the data.% (\figref{quartilefig}).
|
||||||
\entermde[percentile]{Perzentil}{Percentiles} allow to characterize the
|
\entermde[percentile]{Perzentil}{Percentiles} allow to characterize the
|
||||||
distribution of the data in more detail. The 3$^{\rm rd}$ quartile
|
distribution of the data in more detail. The 3$^{\rm rd}$ quartile
|
||||||
corresponds to the 75$^{\rm th}$ percentile, because 75\,\% of the
|
corresponds to the 75$^{\rm th}$ percentile, because 75\,\% of the
|
||||||
@ -156,15 +148,13 @@ median that extends from the 1$^{\rm st}$ to the 3$^{\rm rd}$
|
|||||||
quartile. The whiskers mark the minimum and maximum value of the data
|
quartile. The whiskers mark the minimum and maximum value of the data
|
||||||
set (\figref{displayunivariatedatafig} (3)).
|
set (\figref{displayunivariatedatafig} (3)).
|
||||||
|
|
||||||
\begin{exercise}{univariatedata.m}{}
|
% \begin{figure}[t]
|
||||||
Generate 40 normally distributed random numbers with a mean of 2 and
|
% \includegraphics[width=1\textwidth]{quartile}
|
||||||
illustrate their distribution in a box-whisker plot
|
% \titlecaption{\label{quartilefig} Median and quartiles of a normal
|
||||||
(\code{boxplot()} function), with a bar and errorbar illustrating
|
% distribution.}{ The interquartile range between the first and the
|
||||||
the mean and standard deviation (\code{bar()}, \code{errorbar()}),
|
% third quartile contains 50\,\% of the data and contains the
|
||||||
and the data themselves jittered randomly (as in
|
% median.}
|
||||||
\figref{displayunivariatedatafig}). How to interpret the different
|
% \end{figure}
|
||||||
plots?
|
|
||||||
\end{exercise}
|
|
||||||
|
|
||||||
% \begin{exercise}{boxwhisker.m}{}
|
% \begin{exercise}{boxwhisker.m}{}
|
||||||
% Generate a $40 \times 10$ matrix of random numbers and
|
% Generate a $40 \times 10$ matrix of random numbers and
|
||||||
@ -201,6 +191,16 @@ Histograms are often used to estimate the
|
|||||||
\enterm[probability!distribution]{probability distribution}
|
\enterm[probability!distribution]{probability distribution}
|
||||||
(\determ[Wahrscheinlichkeits!-verteilung]{Wahrscheinlichkeitsverteilung}) of the data values.
|
(\determ[Wahrscheinlichkeits!-verteilung]{Wahrscheinlichkeitsverteilung}) of the data values.
|
||||||
|
|
||||||
|
\begin{exercise}{univariatedata.m}{}
|
||||||
|
Generate 40 normally distributed random numbers with a mean of 2 and
|
||||||
|
illustrate their distribution in a box-whisker plot
|
||||||
|
(\code{boxplot()} function), with a bar and errorbar illustrating
|
||||||
|
the mean and standard deviation (\code{bar()}, \code{errorbar()}),
|
||||||
|
and the data themselves jittered randomly (as in
|
||||||
|
\figref{displayunivariatedatafig}). How to interpret the different
|
||||||
|
plots?
|
||||||
|
\end{exercise}
|
||||||
|
|
||||||
\subsection{Probabilities}
|
\subsection{Probabilities}
|
||||||
In the frequentist interpretation of probability, the
|
In the frequentist interpretation of probability, the
|
||||||
\enterm{probability} (\determ{Wahrscheinlichkeit}) of an event
|
\enterm{probability} (\determ{Wahrscheinlichkeit}) of an event
|
||||||
@ -252,7 +252,7 @@ real number like, e.g., 0.123456789 is zero, because there are
|
|||||||
uncountable many real numbers.
|
uncountable many real numbers.
|
||||||
|
|
||||||
We can only ask for the probability to get a measurement value in some
|
We can only ask for the probability to get a measurement value in some
|
||||||
range. For example, we can ask for the probability $P(1.2<x<1.3)$ to
|
range. For example, we can ask for the probability $P(0<x<1)$ to
|
||||||
get a measurement between 0 and 1 (\figref{pdfprobabilitiesfig}). More
|
get a measurement between 0 and 1 (\figref{pdfprobabilitiesfig}). More
|
||||||
generally, we want to know the probability $P(x_0<x<x_1)$ to obtain a
|
generally, we want to know the probability $P(x_0<x<x_1)$ to obtain a
|
||||||
measurement between $x_0$ and $x_1$. If we define the width of the
|
measurement between $x_0$ and $x_1$. If we define the width of the
|
||||||
@ -280,7 +280,7 @@ inverse of the unit of the data values --- hence the name ``density''.
|
|||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
The probability to get a value $x$ between $x_1$ and $x_2$ is
|
The probability to get a value $x$ between $x_1$ and $x_2$ is
|
||||||
given by the integral of the probability density:
|
given by an integral over the probability density:
|
||||||
\[ P(x_1 < x < x2) = \int\limits_{x_1}^{x_2} p(x) \, dx \; . \]
|
\[ P(x_1 < x < x2) = \int\limits_{x_1}^{x_2} p(x) \, dx \; . \]
|
||||||
Because the probability to get any value $x$ is one, the integral of
|
Because the probability to get any value $x$ is one, the integral of
|
||||||
the probability density over the whole real axis must be one:
|
the probability density over the whole real axis must be one:
|
||||||
@ -329,7 +329,7 @@ values fall within each bin (\figref{pdfhistogramfig} left).
|
|||||||
observe?
|
observe?
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
To turn such histograms to estimates of probability densities they
|
To turn such histograms into estimates of probability densities they
|
||||||
need to be normalized such that according to \eqnref{pdfnorm} their
|
need to be normalized such that according to \eqnref{pdfnorm} their
|
||||||
integral equals one. While histograms of categorical data are
|
integral equals one. While histograms of categorical data are
|
||||||
normalized such that their sum equals one, here we need to integrate
|
normalized such that their sum equals one, here we need to integrate
|
||||||
@ -343,7 +343,7 @@ and the
|
|||||||
\[ p(x_i) = \frac{n_i}{A} = \frac{n_i}{\Delta x \sum_{i=1}^N n_i} =
|
\[ p(x_i) = \frac{n_i}{A} = \frac{n_i}{\Delta x \sum_{i=1}^N n_i} =
|
||||||
\frac{n_i}{N \Delta x} \; .\]
|
\frac{n_i}{N \Delta x} \; .\]
|
||||||
A histogram needs to be divided by both the sum of the frequencies
|
A histogram needs to be divided by both the sum of the frequencies
|
||||||
$n_i$ and the bin width $\Delta x$ to results in an estimate of the
|
$n_i$ and the bin width $\Delta x$ to result in an estimate of the
|
||||||
corresponding probability density. Only then can the distribution be
|
corresponding probability density. Only then can the distribution be
|
||||||
compared with other distributions and in particular with theoretical
|
compared with other distributions and in particular with theoretical
|
||||||
probability density functions like the one of the normal distribution
|
probability density functions like the one of the normal distribution
|
||||||
@ -371,19 +371,20 @@ probability density functions like the one of the normal distribution
|
|||||||
A problem of using histograms for estimating probability densities is
|
A problem of using histograms for estimating probability densities is
|
||||||
that they have hard bin edges. Depending on where the bin edges are
|
that they have hard bin edges. Depending on where the bin edges are
|
||||||
placed a data value falls in one or the other bin. As a result the
|
placed a data value falls in one or the other bin. As a result the
|
||||||
shape histogram depends on the exact position of its bins
|
shape of the resulting histogram depends on the exact position of its
|
||||||
(\figref{kerneldensityfig} left).
|
bins (\figref{kerneldensityfig} left).
|
||||||
|
|
||||||
\begin{figure}[t]
|
\begin{figure}[t]
|
||||||
\includegraphics[width=1\textwidth]{kerneldensity}
|
\includegraphics[width=1\textwidth]{kerneldensity}
|
||||||
\titlecaption{\label{kerneldensityfig} Kernel densities.}{Left: The
|
\titlecaption{\label{kerneldensityfig} Kernel densities.}{The
|
||||||
histogram-based estimation of the probability density is dependent
|
histogram-based estimation of the probability density depends on
|
||||||
on the position of the bins. In the bottom plot the bins have
|
the position of the bins (left). In the bottom plot the bins have
|
||||||
been shifted by half a bin width (here $\Delta x=0.4$) and as a
|
been shifted by half a bin width (here $\Delta x=0.4$) and as a
|
||||||
result details of the probability density look different. Look,
|
result details of the probability density look different. Look,
|
||||||
for example, at the height of the largest bin. Right: In contrast,
|
for example, at the height of the largest bin. In contrast, a
|
||||||
a kernel density is uniquely defined for a given kernel width
|
kernel density is uniquely defined for a given kernel width
|
||||||
(here Gaussian kernels with standard deviation of $\sigma=0.2$).}
|
(right, Gaussian kernels with standard deviation of
|
||||||
|
$\sigma=0.2$).}
|
||||||
\end{figure}
|
\end{figure}
|
||||||
|
|
||||||
To avoid this problem so called \entermde[kernel
|
To avoid this problem so called \entermde[kernel
|
||||||
@ -460,7 +461,6 @@ and percentiles can be determined from the inverse cumulative function.
|
|||||||
Use the estimate to compute the value of the 5\,\% percentile.
|
Use the estimate to compute the value of the 5\,\% percentile.
|
||||||
\end{exercise}
|
\end{exercise}
|
||||||
|
|
||||||
\newpage
|
|
||||||
\section{Correlations}
|
\section{Correlations}
|
||||||
|
|
||||||
Until now we described properties of univariate data sets. In
|
Until now we described properties of univariate data sets. In
|
||||||
|
Reference in New Issue
Block a user