This commit is contained in:
Jan Benda 2020-01-14 17:18:28 +01:00
commit d1c8112030
66 changed files with 285 additions and 361 deletions

View File

@ -12,125 +12,57 @@ figure_height = 6.0 # cm, for a 1 x 2 figure
ppi = 72.0 ppi = 72.0
# colors: # colors:
colors = {}
colors['red'] = '#CC0000'
colors['orange'] = '#FF9900'
colors['lightorange'] = '#FFCC00'
colors['yellow'] = '#FFFF66'
colors['green'] = '#99FF00'
colors['blue'] = '#0000CC'
colors['gray'] = '#A7A7A7'
colors['black'] = '#000000'
#colors_bendalab_vivid['red'] = '#D71000'
#colors_bendalab_vivid['orange'] = '#FF9000'
#colors_bendalab_vivid['yellow'] = '#FFF700'
#colors_bendalab_vivid['green'] = '#30D700'
#colors_bendalab_vivid['blue'] = '#0020C0'
def lighter(color, lightness): # line styles for plot():
""" Make a color lighter. lwthick = 4.0
lwthin = 2.0
fillalpha = 0.5
Parameters # helper lines:
---------- lsSpine = {'c': colors['black'], 'linestyle': '-', 'linewidth': 1}
color: string lsGrid = {'c': colors['gray'], 'linestyle': '--', 'linewidth': 1}
An RGB color as a hexadecimal string (e.g. '#rrggbb'). lsMarker = {'c': colors['black'], 'linestyle': '-', 'linewidth': 2}
lightness: float
The smaller the lightness, the lighter the returned color.
A lightness of 1 leaves the color untouched.
A lightness of 0 returns white.
Returns # line styles and fill styles:
------- lsA = {'color': colors['blue'], 'linestyle': '-', 'linewidth': lwthick}
color: string lsAm = {'color': colors['blue'], 'linestyle': '-', 'linewidth': lwthin}
The lighter color as a hexadecimal RGB string (e.g. '#rrggbb'). fsAa = {'facecolor': colors['blue'], 'edgecolor': 'none', 'alpha': fillalpha}
"""
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)
lsB = {'color': colors['red'], 'linestyle': '-', 'linewidth': lwthick}
lsBm = {'color': colors['red'], 'linestyle': '-', 'linewidth': lwthin}
fsB = {'facecolor': colors['red'], 'edgecolor': colors['black'], 'linewidth': 1}
fsBs = {'facecolor': colors['red'], 'edgecolor': 'none'}
fsBa = {'facecolor': colors['red'], 'edgecolor': 'none', 'alpha': fillalpha}
def darker(color, saturation): lsC = {'color': colors['lightorange'], 'linestyle': '-', 'linewidth': lwthick}
""" Make a color darker. lsCm = {'color': colors['lightorange'], 'linestyle': '-', 'linewidth': lwthin}
fsC = {'facecolor': colors['lightorange'], 'edgecolor': colors['black'], 'linewidth': 1}
fsCs = {'facecolor': colors['lightorange'], 'edgecolor': 'none'}
fsCa = {'facecolor': colors['lightorange'], 'edgecolor': 'none', 'alpha': fillalpha}
Parameters fsD = {'facecolor': colors['orange'], 'edgecolor': colors['black'], 'linewidth': 1}
---------- fsDs = {'facecolor': colors['orange'], 'edgecolor': 'none'}
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)
fsE = {'facecolor': colors['yellow'], 'edgecolor': colors['black'], 'linewidth': 1}
fsEs = {'facecolor': colors['yellow'], 'edgecolor': 'none'}
# colors: fsF = {'facecolor': colors['green'], 'edgecolor': colors['black'], 'linewidth': 1}
colors = { fsFs = {'facecolor': colors['green'], 'edgecolor': 'none'}
'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():
lsSpine = {'c': colors['black'], 'linestyle': '-', 'linewidth': 1}
lsGrid = {'c': colors['grey'], 'linestyle': '--', 'linewidth': 1}
# 'B1': prominent line with first color and style from color group 'B'
# 'C2m': minor line with second color and style from color group 'C'
ls = {
'A1': {'c': colors['red'], 'linestyle': '-', 'linewidth': 3},
'A2': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 3},
'A3': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 3},
'B1': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 3},
'B2': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 3},
'B3': {'c': colors['yellow'], 'linestyle': '-', 'linewidth': 3},
'C1': {'c': colors['green'], 'linestyle': '-', 'linewidth': 3},
'D1': {'c': colors['blue'], 'linestyle': '-', 'linewidth': 3},
'A1m': {'c': colors['red'], 'linestyle': '-', 'linewidth': 2},
'A2m': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 2},
'A3m': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 2},
'B1m': {'c': colors['orange'], 'linestyle': '-', 'linewidth': 2},
'B2m': {'c': colors['lightorange'], 'linestyle': '-', 'linewidth': 2},
'B3m': {'c': colors['yellow'], 'linestyle': '-', 'linewidth': 2},
'C1m': {'c': colors['green'], 'linestyle': '-', 'linewidth': 2},
'D1m': {'c': colors['blue'], 'linestyle': '-', 'linewidth': 2},
}
# 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
@ -369,14 +301,12 @@ def common_format():
if 'axes.prop_cycle' in mpl.rcParams: if 'axes.prop_cycle' in mpl.rcParams:
from cycler import cycler 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__

View File

@ -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

View File

@ -0,0 +1,3 @@
ZIPFILES=
include ../project.mk

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
ZIPFILES=
include ../project.mk

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,34 @@
clear all
close all
data = load('Username_2019-05-22_001.mat');
IV_protnum = [25];
STP_protnum = [26, 27, 28, 29, 30];
IV = sortData(data, IV_protnum);
STP = sortData(data, STP_protnum);
IV_steps = -90:10:50;
save 'IV.mat' IV
save 'IV_steps.mat' IV_steps
save 'STP.mat' STP
% for i = 1:length(STP)
% for j = 1:length(STP{i})
% figure(j)
% hold on
% plot(STP{i}{j}(:,1),STP{i}{j}(:,2))
% hold off
% end
% end
%
% for i = 1:length(IV)
% for j = 1:length(IV{i})
% figure(j)
% hold on
% plot(IV{i}{j}(:,1),IV{i}{j}(:,2))
% hold off
% end
% end

View File

@ -0,0 +1,20 @@
function C = sortData(data, protnums)
names = fieldnames(data);
C = cell(1,length(protnums));
for i = 1:length(protnums)
idxvec = zeros(1,length(names));
for j = 1:length(names)
idxvec(j) = strcmp(names{j}(1:10), ['Trace_1_', num2str(protnums(i))]);
end
c = cell(1,sum(idxvec));
idxvec = find(idxvec);
for j = 1:length(idxvec)
c{j} = data.(names{idxvec(j)});
end
C{i} = c;
end

View File

@ -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,39 +15,31 @@ 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()
fig = plt.figure( figsize=(6, 2.4) ) ax.set_xlabel('x')
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_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( 'F(x)' ) ax.set_ylabel('F(x)')
ax.set_ylim(-0.05, 1.05) 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, **lsMarker)
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, **lsMarker)
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, **lsMarker)
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()

View File

@ -1,39 +1,30 @@
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)
x1 = rng.random_integers( 1, 6, 100 ) 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=1, **lsAm)
ax.set_xlim(0, 7) ax2.hist([x2, x1], bins, normed=True, zorder=10, **fs)
ax.set_xticks( range(1, 7) ) fig.savefig('diehistograms.pdf')
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' )
#plt.show()

View File

@ -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.4*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,19 +48,14 @@ 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.set_xlim(0.0, 4.8)
ax.set_ylabel('x')
ax.set_ylim( 0.0, 8.0)
ax = fig.add_subplot(spec[0, 0])
ax.set_xlim(0.0, 4.8)
ax.set_xticks([scatterpos, barpos, boxpos]) ax.set_xticks([scatterpos, barpos, boxpos])
ax.set_xticklabels(['(1) data', '(2) bar\n plot', '(3) box-\nwhisker']) ax.set_xticklabels(['(1) data', '(2) bar\n plot', '(3) box-\nwhisker'])
ax.set_ylabel('x')
ax.set_ylim( 0.0, 8.0)
# scatter data points according to their density: # scatter data points according to their density:
kernel = gaussian_kde(data) kernel = gaussian_kde(data)
@ -80,11 +66,10 @@ ax.scatter(scatterpos+barwidth*x*(rng.rand(len(data))-0.5), data, s=50)
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,11 +81,7 @@ 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))
@ -108,8 +89,7 @@ ax.set_xlabel('(4) p(x)')
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()

View File

@ -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() fig.savefig('median.pdf')
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' )
#plt.show()

View File

@ -1,44 +1,31 @@
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)
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)
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 ) fig.savefig('pdfhistogram.pdf')
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' )
#plt.show()

View File

@ -1,36 +1,28 @@
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)
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)
x1=0.0 x1=0.0
x2=1.0 x2=1.0
plt.xkcd() fig, ax = plt.subplots()
fig = plt.figure( figsize=(6,3.4) ) ax.set_xlabel('x')
ax = fig.add_subplot( 1, 1, 1 ) ax.set_ylabel('Probability density p(x)')
ax.spines['right'].set_visible(False) ax.set_ylim(0.0, 0.46)
ax.spines['top'].set_visible(False) ax.set_yticks(np.arange(0.0, 0.45, 0.1))
ax.yaxis.set_ticks_position('left')
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_ylabel( 'Probability density p(x)' )
ax.set_ylim( 0.0, 0.46 )
ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
ax.annotate('Gaussian', ax.annotate('Gaussian',
xy=(-1.0, 0.28), xycoords='data', xy=(-1.0, 0.28), xycoords='data',
xytext=(-2.5, 0.35), textcoords='data', ha='left', xytext=(-2.5, 0.35), textcoords='data', ha='left',
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() fig.savefig('pdfprobabilities.pdf')
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' )
#plt.show()

View File

@ -1,22 +1,18 @@
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.2*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.set_xlabel('x')
ax.spines['right'].set_visible(False) ax.set_ylabel('Probability density p(x)')
ax.spines['top'].set_visible(False) ax.set_ylim(0.0, 0.46)
ax.yaxis.set_ticks_position('left') ax.set_yticks(np.arange(0.0, 0.45, 0.1))
ax.xaxis.set_ticks_position('bottom')
ax.set_xlabel( 'x' )
ax.set_ylabel( 'Probability density p(x)' )
ax.set_ylim( 0.0, 0.46 )
ax.set_yticks( np.arange( 0.0, 0.45, 0.1 ) )
ax.text(-1.2, 0.1, '25%', ha='center' ) ax.text(-1.2, 0.1, '25%', ha='center' )
ax.text(-0.35, 0.1, '25%', ha='center' ) ax.text(-0.35, 0.1, '25%', ha='center' )
ax.text(+0.35, 0.1, '25%', ha='center' ) ax.text(+0.35, 0.1, '25%', ha='center' )
@ -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()