TransWikia.com

Nodes in pgfplots

TeX - LaTeX Asked on July 27, 2021

I wanna plot the density of a normal distribution as it is in the pic below. The Problems:

  • the node t=1,63 does not appear in the plot
  • do not know how to draw the arrow in an easy way

Here’s my code so far:

documentclass[a4paper,11pt,fleqn]{scrartcl}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage{lmodern}
usepackage{ntheorem}
usepackage{here}
usepackage{multirow}
usepackage{eurosym}
usepackage{pgf,tikz}
usetikzlibrary{arrows,shadows}
pagestyle{empty}
usepackage{graphicx}
usepackage{array}
usetikzlibrary{decorations.pathreplacing} 
usepackage{colortbl}
usepackage[ngerman]{babel}
usepackage{geometry}
geometry{a4paper, top=15mm, left=25mm, right=25mm, bottom=20mm,
 headsep=10mm, footskip=12mm}
theoremstyle{break}
usepackage{amsfonts}
usepackage{color}  
usepackage{gauss}
usepackage{pgfplots}
usepackage{tikz}
usepackage{gensymb}
usepackage{systeme}
usepackage{pgf,tikz}
usetikzlibrary{arrows}
pagestyle{empty}
usepackage{booktabs}
usetikzlibrary{positioning,fit,calc}
usetikzlibrary{backgrounds}
usepackage{amssymb}
usepackage{amsmath}
addtokomafont{caption}{footnotesize}
setlength{mathindent}{0pt}
makeatletter
g@addto@macronormalsize{%  <----
 setlengthabovedisplayskip{0pt}%  <----
 setlengthbelowdisplayskip{10pt}%  <----
 setlengthabovedisplayshortskip{0pt}%  <----
setlengthbelowdisplayshortskip{20pt}%  <----
}
 makeatother
 setlength{intextsep}{0pt}
  tikzset{declare function={
    normcdf(x,m,s)=1/(1 + exp(-0.07056*((x-m)/s)^3 - 1.5976*     (x-m)/s));
}}
       pgfmathdeclarefunction{gauss{2}{%pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%}

usepackage{tabularx}
newcolumntype{L}[1]{>{raggedrightarraybackslash}p{#1}} % linksbündig mit Breitenangabe
newcolumntype{C}[1]{>{centeringarraybackslash}p{#1}} % zentriert mit Breitenangabe
newcolumntype{R}[1]{>{raggedleftarraybackslash}p{#1}} % rechtsbündig mit Breitenangabe

newcommand*xbar[1]{%
 hbox{%
  vbox{%
  hrule height 0.5pt % The actual bar
  kern0.5ex%         % Distance between bar and symbol
  hbox{%
    kern-0.1em%      % Shortening on the left side
    ensuremath{#1}%
    kern-0.1em%      % Shortening on the right side}%}%}%}

 usepackage{etoolbox}
makeatletter
patchcmdg@matrix
 {vboxbgroup}
 {vboxbgroupnormalbaselines}% restore the standard baselineskip
{}{}
makeatother


 newcommand{BAR}{%
  hspace{-arraycolsep}%
  strutvrule % the `vrule` is as high and deep as a strut
 hspace{-arraycolsep}%
  }

    usepackage{tabstackengine}[2016-10-04]
  stackMath


begin{document}
begin{figure}[H]
    centering
begin{tikzpicture}
begin{axis}[ domain=-1:1,
         scale only axis,
         axis x line=middle,
         axis y line=middle,
         inner axis line style={=>},
                 width=15cm,height=6cm,
                ymin=0,ymax=0.45,
                xmin=-3.5,xmax=3.5,
                axis line style = thick,
                xtick={-3,-2,-1,1,2,3},
                ytick={0.1,0.2,0.3,0.4},
        every axis x label/.style={at={(current axis.right of origin)},anchor=west},
         every axis y label/.style={at={(current axis.north)},above=0.5mm},
                 xlabel={$x$},
                 ylabel={$f(x)$},
                    axis on top]
      addplot[fill=blue!25,draw=none,domain=-3.5:-1.63] {gauss(0,1)}     closedcycle;]
addplot[fill=blue!25,draw=none,domain=1.63:3.5] {gauss(0,1)} closedcycle;]
addplot [domain=-3.5:3.5,samples=500,red,thick] {gauss(0,1)};
node at (axis cs:1.63,-0.05){$t=1.63$};
end{axis}
end{tikzpicture}
caption{Graph der Dichtefunktion $f_X(x)$ mit $Xsimmathcal{N}(0,1)$}%
end{figure}
 end{document}

enter image description here

One Answer

like this?

enter image description here

note: for present of your Gaussian the most of preamble in your minimal working example is superfluous. i omit all what is not needed for present it.

edit: after reinspected your image i found that extra x tick label $stackrel{uparrow}{t=1.63}$ is not logical. abscissa is labeld x, so it should be sufficient to label this point only with number. if you like to emphasize it, you can change its color or face/shape. corrected.

documentclass[a4paper,11pt,fleqn]{scrartcl}

usepackage{pgfplots}
pgfplotsset{compat=1.15}
pgfmathdeclarefunction{gauss}{2}{%
    pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
                                }
usetikzlibrary{arrows.meta}    % <--- added

begin{document}
    begin{figure}[htb]
    centering
begin{tikzpicture}[
    every pin/.style = {pin edge={Latex-,thin,black}}
                    ]
begin{axis}[
    width=15cm,height=6cm,
        scale only axis,
        axis lines=middle,
        ymin=0,ymax=0.45,
        axis line style = thick,
        xtick={-3,-2,-1,1,2,3},
        extra x ticks ={1.63},
        extra x tick labels ={color{blue}1.63},
        x label style={anchor=west},
        y label style={anchor=south},
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top,
        samples=50]
addplot[fill=blue!25,draw=none,domain=-3.5:-1.63] {gauss(0,1)} closedcycle;
addplot[fill=blue!25,draw=none,domain=1.63:3.5]   {gauss(0,1)} closedcycle;
addplot[domain=-3.5:3.5,red,thick] {gauss(0,1)};
node [pin= 60:$P_{val}/2$] at ( 2,0.02)   {};
node [pin=120:$P_{val}/2$] at (-2,0.02)   {};
end{axis}
end{tikzpicture}
caption{Graph der Dichtefunktion $f_X(x)$ mit $Xsimmathcal{N}(0,1)$}%
    end{figure}
end{document}

edit: since you insist in your arrow and labels ...

documentclass[a4paper,11pt,fleqn]{scrartcl}

usepackage{pgfplots}
pgfplotsset{compat=1.15}
pgfmathdeclarefunction{gauss}{2}{%
    pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
                                }
usetikzlibrary{arrows.meta}    % <--- added

begin{document}
    begin{figure}[htb]
    centering
begin{tikzpicture}[
    every pin/.style = {pin edge={Latex-,thin,black}}
                    ]
begin{axis}[
    width=15cm,height=6cm,
        scale only axis,
        axis lines=middle,
        ymin=0,ymax=0.45,
        axis line style = thick,
        xtick={-3,-2,-1,1,2,3},
        x label style={anchor=west},
        y label style={anchor=south},
        xlabel={$x$},
        ylabel={$f(x)$},
        axis on top,
        samples=50,
        clip=false]
addplot[fill=blue!25,draw=none,domain=-3.5:-1.63] {gauss(0,1)} closedcycle;
addplot[fill=blue!25,draw=none,domain=1.63:3.5]   {gauss(0,1)} closedcycle;
addplot[domain=-3.5:3.5,red,thick] {gauss(0,1)};
node [pin= 60:$P_{val}/2$] at ( 2,0.02)   {};
node [pin=120:$P_{val}/2$] at (-2,0.02)   {};
node [below,pin=below:{$t=1.63$}] at (1.63,0.01)   {};
end{axis}
end{tikzpicture}
caption{Graph der Dichtefunktion $f_X(x)$ mit $Xsimmathcal{N}(0,1)$}%
    end{figure}
end{document}

enter image description here

edit (2): a variation of above image code. if you replace

node [pin= 60:$P_{val}/2$] at ( 2,0.02)   {};
node [pin=120:$P_{val}/2$] at (-2,0.02)   {};
node [below,pin=below:{$t=1.63$}] at (1.63,0.01)   {};

with

coordinate[pin= 60:$P_{val}/2$] (x) at ( 2,0.02);
coordinate[pin=120:$P_{val}/2$] (x) at (-2,0.02);
coordinate[pin=below:{$t=1.63$}](x) at ( 1.63,0);

you will obtain:

enter image description here

Correct answer by Zarko on July 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP