Gaussian Probability: 1 to 2 in tikz

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
7 replies · 2K views
karush
Gold Member
MHB
Messages
3,240
Reaction score
5
\begin{tikzpicture}[scale=0.6]
%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,2},
xticklabels={$1$,$2$},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {\gauss{0}{1}} \closedcycle;
\addplot {\gauss{0}{1}};
\end{axis}
\end{tikzpicture}

ok this was for P(1<z<2) scaled the graph to .6
the ultimate answer of course is the area in the domain which I don't know if we can derive from the gauss{}{} function
I tried to put the newcommand quass{}{} in the preamble of Overleaf but it didn't take
also thot since all 12 of homework problem are just graphing P()
be nice just have a newcommand \Pg with arguments but also need code that can be colabortive with Overleaf and MHB

again mega mahalo for all the help
 
on Phys.org
this is what it looks like in Overleaf...

Screenshot 2021-08-13 11.20.21 AM.png
 
ok well that seems to an advantage of desmos over tikz except tikz is much more exotic
 
Last edited:
karush said:
ok well that seem to an advantage of desmos over tikz except tikz is much more exotic
It appears I misunderstood your question somehow.
Desmos does not have such ability either.
Can you clarify what you want?
 
well i have graph i wanted
i was just curious about integration function in tikx

but yes desmos has a integration function its under misc in the function menu
i have used it many times
 
Well, with a bit of trickery, we can do:
\begin{tikzpicture}[scale=1,
declare function={
gauss(\x,\mean,\sigma) = 1/(\sigma*sqrt(2*pi))*exp(-(\x-\mean)^2/(2*\sigma^2));
normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
},
]
%preamble \usepackage{pgfplots}
\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,2},
width=10cm,
height=4cm]
\addplot [fill=cyan!30, draw=none, domain=1:2] {gauss(x,0,1)} \closedcycle;
\addplot {gauss(x,0,1)};
\path foreach \y [evaluate=\y as \yeval using {normcdf(\y,0,1)-normcdf(1,0,1)}] in {2} { node[ left ] at (axis cs:{\y},0.05) {\yeval} };
\end{axis}
\end{tikzpicture}

It uses
Code:
[declare function={
    normcdf(\x,\m,\s)=1/(1 + exp(-0.07056*((\x-\m)/\s)^3 - 1.5976*(\x-\m)/\s));
}]
to approximate the area under the Gaussian graph.

And it uses evaluate=\y as \yeval using syntax to convert the function call into a value before printing it.
 
wow that is pretty cool...