[Tex/LaTex] tikz: plot stepped gauss

gnuplotplottikz-pgf

I need to plot a stepped gauss curve as shown below. Yet I want to do this dynamically (in text) so I can alter it later.

http://media.texample.net/tikz/examples/PDF/gnuplot-tikz-terminal.pdf

I know how to plot a smooth gauss but I really need the stepped one. Also a bar (option ybar) won't do because I only need the contour of the bar plot (no bars, just one curve).

I've tried:

\draw[black,thick] plot[id=gg,raw gnuplot] function{
    set xrange [0:7.5];
    set samples 30;
    normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2);
    invsqrt2pi = 0.398942280401433;
    plot 3.5*normal(x,1.5,0.5) with histeps;
};

yet the histeps option from gnu plot doesn't kick in… (this script does work when in gnuplot).

Best Answer

When you use gnuplot in TikZ, all that happens is that you get gnuplot to generate a series of points in a table that is read and rendered using TikZ. The histeps option doesn't change the data, but only the rendering (in gnuplot), so it doesn't influence what you see in TikZ. Instead, you can use the TikZ option const plot:

\draw[black,thick] plot[id=gg,raw gnuplot, const plot] function{
    set xrange [0:7.5];
    set samples 30;
    normal(x,mu,sigma)=sigma<=0?1/0:invsqrt2pi/sigma*exp(-0.5*((x-mu)/sigma)**2);
    invsqrt2pi = 0.398942280401433;
    plot 3.5*normal(x,1.5,0.5);
};
Related Question