Pgfplots箱線圖:更改離群值樣式

Pgfplots箱線圖:更改離群值樣式

我正在嘗試繪製幾個箱線圖(從文件中讀取的資料),我希望它們看起來相同。我設法對除異常值之外的所有內容執行此操作,仍然使用預設樣式/顏色圖(請參閱下圖)。

我怎樣才能改變他們的外表?

在此輸入影像描述

微量元素

\documentclass{minimal}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}

\begin{document}

   \begin{tikzpicture}
   \begin{axis}[y=1cm]
      \foreach \n in {1,...,8}
      {
      \addplot+ [boxplot,draw=black,solid,fill=white] table [row sep=\\,y index=0] 
         {
         data\\
         1\\ 2\\ 1\\ 5\\ 20\\ 10\\
         7\\ 10\\ 9\\ 8\\ 9\\ 9\\
         };
      }
   \end{axis}
   \end{tikzpicture}
\end{document}

答案1

有很多方法可以實現您想要的目標。一種方法是建立自訂樣式並向其中添加所有選項/鍵。

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \usepgfplotslibrary{statistics}
    \pgfplotsset{
        compat=1.3,
        % create a custom style for the boxplots
        my boxplot style/.style={
            boxplot,
            draw=black,
            solid,
            fill=white,
            % -------------------------------------------------------------
            % add your desired mark symbol and mark style here
            mark=*,
            every mark/.append style={
                fill=gray,
            },
            % -------------------------------------------------------------
        },
    }
\begin{document}
\begin{tikzpicture}
   \begin{axis}
        \foreach \n in {1,...,8} {
            \addplot+ [
                % apply the custom style
                my boxplot style,
            ] table [row sep=\\,y index=0] {
                data\\
                1\\ 2\\ 1\\ 5\\ 20\\ 10\\
                7\\ 10\\ 9\\ 8\\ 9\\ 9\\
            };
        }
   \end{axis}
\end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

相關內容