Skip to content

Instantly share code, notes, and snippets.

@JavierJia
Created April 10, 2017 18:42
Show Gist options
  • Save JavierJia/e10f7c7d8ce3c42a6e469316a5738f0f to your computer and use it in GitHub Desktop.
Save JavierJia/e10f7c7d8ce3c42a6e469316a5738f0f to your computer and use it in GitHub Desktop.
gnuplot histogram and normal distribution
set key left box
set autoscale
set samples 800
set terminal postscript eps enhanced size 3in,3in color
set x2range [-10 : 8]
set ytics nomirror
set y2tics
set autoscale y
set autoscale y2
invsqrt2pi = 0.398942280401433
normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2)
binwidth=0.3
bin(x,width)=width*floor(x/width)
plot 'var.dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes notitle, \
normal(x,0,1.4) axes x2y2 with lines lw 2 notitle
# normal(x,0,1) axes x2y2 with lines lw 2 title "a good fit", \
@jnares
Copy link

jnares commented Nov 20, 2018

set key left box
set autoscale
set samples 800
set terminal postscript eps enhanced size 3in,3in color

set x2range [-10 : 8]
set ytics nomirror
set y2tics
set autoscale y
set autoscale y2

invsqrt2pi = 0.398942280401433
normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigmaexp(-0.5((x-mu)/sigma)**2)

binwidth=0.3
bin(x,width)=width*floor(x/width)
plot 'var.dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes notitle,
normal(x,0,1.4) axes x2y2 with lines lw 2 notitle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment