pgfplots 中的节点

pgfplots 中的节点

我想绘制正态分布的密度,如下图所示。问题:

  • 节点 t=1,63 未出现在图中
  • 不知道如何轻松地绘制箭头

这是我目前的代码:

\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@macro\normalsize{%  <----
 \setlength\abovedisplayskip{0pt}%  <----
 \setlength\belowdisplayskip{10pt}%  <----
 \setlength\abovedisplayshortskip{0pt}%  <----
\setlength\belowdisplayshortskip{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]{>{\raggedright\arraybackslash}p{#1}} % linksbündig mit Breitenangabe
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}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
\patchcmd\g@matrix
 {\vbox\bgroup}
 {\vbox\bgroup\normalbaselines}% restore the standard baselineskip
{}{}
\makeatother


 \newcommand{\BAR}{%
  \hspace{-\arraycolsep}%
  \strut\vrule % 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 $X\sim\mathcal{N}(0,1)$}%
\end{figure}
 \end{document}

在此处输入图片描述

答案1

像这样?

在此处输入图片描述

注意:对于您的高斯来说,最小工作示例中的大部分前言都是多余的。我省略了所有不需要的内容。

编辑:重新检查您的图像后,我发现额外的 x 刻度标签$\stackrel{\uparrow}{t=1.63}$是不合逻辑的。横坐标已标记x,因此仅用数字标记该点就足够了。如果您想强调它,可以更改其颜色或面/形状。已更正。

\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 $X\sim\mathcal{N}(0,1)$}%
    \end{figure}
\end{document}

编辑: 因为你坚持你的箭头和标签......

\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 $X\sim\mathcal{N}(0,1)$}%
    \end{figure}
\end{document}

在此处输入图片描述

编辑(2):上述图片代码的变体。如果你替换

\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)   {};

\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);

你将获得:

在此处输入图片描述

相关内容