我怎样才能将节点放到箱线图中的异常值中?

我怎样才能将节点放到箱线图中的异常值中?

我终于成功得到了我想要的箱线图,但现在我不知道如何标记我的异常值。有人有解决方案吗?

我还想将 y 轴的标记从 .5 步改为 .2 步。我该怎么做?

\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}\begin{figure}
\begin{document}
    \caption{Differnces between votings of external and internal auditors}
    \label{fig:Boxplot}
    \centering
    \begin{tikzpicture}

      \begin{axis}
        [ylabel =
            {$|\overline{x}\textsubscript{item}_i(internal)-\overline{x}\textsubscript{item}_i(external)|$ },
        boxplot/draw direction=y,
        xtick={1},
        xticklabels={Differences},
        x tick label style={font=\footnotesize, text width=1cm, align=center}
        ]
        \addplot+
        [mark = x, mark options = {grey},
        boxplot prepared={
        lower whisker=  0.007834,
        lower quartile= 0.1547,
        median=         0.257,
        average=        0.3763,
        upper quartile= 0.4913,
        upper whisker=  0.8585
        }, color = blue
        ]
       coordinates{(0,1.035) (0,1.194)(0,1.491)}
        node[right] at (boxplot box cs: \boxplotvalue{average}, .5),
        node[right] at (boxplot box cs: \boxplotvalue{1.035}, .5)
        {\boxplotvalue{average}}
        ;
        \end{axis}
    \end{tikzpicture}
    \end{figure}
\end{document}

答案1

根据您具体需要,您或许可以使用nodes near coords。您是否希望将值打印在异常值旁边,还是其他内容?

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
        ylabel =
            {$|\overline{x}_{\text{item}i} (\text{internal})-\overline{x}_{\text{item}i} (\text{external})|$ },
        boxplot/draw direction=y,
        xtick={1},
        xticklabels={Differences},
        x tick label style={
           font=\footnotesize,
           text width=1cm,
           align=center
        },
        % set distance between yticks
        ytick distance=0.2
        ]
        \addplot+
        [mark = x, mark options = {mark color=grey},
        boxplot prepared={
        lower whisker=  0.007834,
        lower quartile= 0.1547,
        median=         0.257,
        average=        0.3763,
        upper quartile= 0.4913,
        upper whisker=  0.8585
        }, color = blue,
        % activate nodes near coords -- makes a node with the meta value next to the point
        nodes near coords,
        % put the node right of the point
        nodes near coords align=right,
        ]
       coordinates{
           (0,1.035) 
           (0,1.194) 
           (0,1.491) 
       }
      node[right] at (boxplot box cs: \boxplotvalue{average}, .5) {\pgfmathprintnumber{\boxplotvalue{average}}}
      ;

      \end{axis}
    \end{tikzpicture}
\end{document}

相关内容