箱线图缩放

箱线图缩放
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    [
    ytick={1,2,3},
    yticklabels={PT,RP-T,P-T},
    % xticklabels={1,2,3,4,5,6,7,a},
    ]
    \addplot+[
    boxplot prepared={
      median=-0.052077,
      upper quartile=1.627744,
      lower quartile=-1.613357,
      upper whisker=9.878565,
      lower whisker=-8.484539
    },
    ] coordinates {};
    \addplot+[
    boxplot prepared={
      median=0.893359,
      upper quartile=32.047894,
      lower quartile=-29.725945,
      upper whisker=219.879028,
      lower whisker=-242.360413
    },
    ] coordinates {};
    \addplot+[
    boxplot prepared={
      median=357.228912,
      upper quartile=32866.879883,
      lower quartile=-31571.360840,
      upper whisker=149471.640625,
      lower whisker=-147415.8125
    },
    ] coordinates {};
  \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

我想很好地展示每个数据范围,但每个数据范围之间的差距太大,以至于两个箱线图看起来只是实心的。我尝试缩小数据范围,并在刻度上用指数符号代替,但这很尴尬,因为要表达的图形范围很窄。对我来说有什么好办法吗?

答案1

因为这里不能切换到对数刻度,我建议进行某种分割绘图,如下所示。备注:

  • 将整体轴复制成 3 个单独的轴
  • 把每个插入物都放进去scope,例如放置
  • 为每个指定宽度和高度
  • 画一些线/箭头来表示某种放大

为了拍出一张漂亮的照片还剩下一些任务要做:

  • 选择更好的最小/最大值,因此所有“0”将居中对齐
  • 找到一种方法为每个范围分配全局名称以简化绘图,例如\draw (A.south) -- (B.north west);,其中(A)是第一个范围,(B)是第二个范围

最后的建议:在类中创建此绘图standalone并使用包graphicx将所述 pdf 作为图像包含在您选择的文档类中。

结果

\documentclass{article}
%\usepackage{graphicx} % Required for inserting images
%\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}[
    >={Stealth},
    ind/.style={->, teal!50},
]
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{scope}
  \begin{axis}
    [
        ytick={1},
        yticklabels={PT},
        % xticklabels={1,2,3,4,5,6,7,a},
        height=4cm, width=10cm,
    ]
    \addplot+[
        boxplot prepared={
          median=357.228912,
          upper quartile=32866.879883,
          lower quartile=-31571.360840,
          upper whisker=149471.640625,
          lower whisker=-147415.8125
    },
    ] coordinates {};
  \end{axis} 
 \end{scope}
 
 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{scope}[yshift=-4cm]
  \begin{axis}
    [
        ytick={1},
        yticklabels={RP-T},
        % xticklabels={1,2,3,4,5,6,7,a},
        height=4cm, width=10cm,
    ]
    \addplot+[
    boxplot prepared={
      median=0.893359,
      upper quartile=32.047894,
      lower quartile=-29.725945,
      upper whisker=219.879028,
      lower whisker=-242.360413
    },
    ] coordinates {};
  \end{axis} 
 \end{scope}
 
 % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 \begin{scope}[yshift=-8cm]
  \begin{axis}
    [
        ytick={1},
        yticklabels={P-T},
        % xticklabels={1,2,3,4,5,6,7,a},
        height=4cm, width=10cm,
    ]
    \addplot+[
    boxplot prepared={
      median=-0.052077,
      upper quartile=1.627744,
      lower quartile=-1.613357,
      upper whisker=9.878565,
      lower whisker=-8.484539
    },
    ] coordinates {};
  \end{axis} 
 \end{scope}
  
  % ~~~ drawing some lines ~~~~~~~~~~~~
  \draw[ind] (4.2,- .5) -- (0,-1.5);
  \draw[ind] (4.2,-4.5) -- (0,-5.5);
  
  \draw[ind] (4.3,- .5) -- (8.5,-1.5);
  \draw[ind] (4.5,-4.5) -- (8.5,-5.5);
  
\end{tikzpicture}

\end{document}

相关内容