TikZ Gaussian curve with shaded tail for P(z>1.28)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
karush
Gold Member
MHB
Messages
3,240
Reaction score
5
ok I was able to get the graph of P(z>1.28)

\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} % Gauss function, parameters mu and sigma
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4] % Default for all plots: from -4:4
%\node [below] at (1.28,0) {$a$};%
\addplot [fill=cyan!30, draw=none, domain=1.28:4] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}

but... most Gauss curves i see are about half this high
and usually only the domain ticks are shown
in this case only 1.28 needs be shown
really don't need what is here on the x-axis
since is basically already understood

also this code was c/p from Overleaf which is very common Latex editor among Universities

MHB has been a great help on this
 
Last edited:
Physics news on Phys.org
We can set custom tick marks and/or labels with xtick respectively xticklabels.
And we can change the height with height, in which case we will also want to set the width because otherwise the picture is just scaled.

If we do so, we get:
Code:
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} % Gauss function, parameters mu and sigma
\begin{axis}[every axis plot post/.append style={
  mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1.28},
xticklabels={$a$},
width=10cm,
height=4cm
]
\addplot [fill=cyan!30, draw=none, domain=1.28:4] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
%preamble \usepackage{pgfplots}
\newcommand\gauss[2]{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))} % Gauss function, parameters mu and sigma
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth}, % All plots: 50 samples, smooth, no marks
axis x line*=bottom, % no box around the plot, only x axis
axis y line=none, % the * suppresses the arrow tips
enlargelimits=upper, % extend the axes a bit to the right and top
domain=-4:4, % Default for all plots: from -4:4
xtick={1.28},
xticklabels={$a$},
width=10cm,
height=4cm
]
\addplot [fill=cyan!30, draw=none, domain=1.28:4] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}
 
that looks great

i went all over the place to find help with this graph
but the one stop help was here at MHB:cool: