箱線圖縮放

箱線圖縮放
\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 個單獨的軸
  • 將每個 insied a 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}

相關內容