如何从一个csv绘制多个箱线图

如何从一个csv绘制多个箱线图

我有 3 个 CSV 文件(teapot.csv、cube.csv 和 sphere.csv)

它们看起来都像这样:

duration,x,y,z,norm
13506,0.763489,0.21941,0.571625,0.978678365
25162,1.466019,-0.222542,1.588425,2.172977365
9083,1.901184,-0.977882,1.170418,2.437341195
10622,1.819077,-0.501896,1.038895,2.154122454
13370,2.756989,-0.097477,1.579063,3.178667971
[many more lines]

我想要一个像这样的图表(即使没有平均值): 在此处输入图片描述

此图是通过准备箱线图获得的,这迫使我预先计算每个值并手动输入。我要绘制多个类似的图表,而这是我想要避免的方法。

所以我尝试了类似的方法:

\begin{tikzpicture}
\pgfplotsset{
        width=13cm,
        height=8cm,
    }
\begin{axis}[
    xlabel={distance (cm)}, 
    title={Location comparison}, 
    ytick={1,2,3,5,6,7,9,10,11,13,14,15},
    yticklabels={\textcolor{red}{teapot},
        delta X \quad \textcolor{green}{cube}, 
        \textcolor{blue}{sphere},
        \textcolor{red}{teapot},
        delta Y \quad \textcolor{green}{cube}, 
        \textcolor{blue}{sphere},
        \textcolor{red}{teapot},
        delta Z \quad \textcolor{green}{cube}, 
        \textcolor{blue}{sphere},
        \textcolor{red}{teapot},
        norm \quad \textcolor{green}{cube}, 
        \textcolor{blue}{sphere}
    }
]
% delta X
\addplot [mark = *, mark options = {red}, 
    boxplot={draw position=1}, 
    color = red
    ] table[x=x,col sep=comma] {Figures/csv/teapot.csv};
\addplot [ 
    boxplot={draw position=2}, 
    color = green
    ] table[x=x,col sep=comma] {Figures/csv/cube.csv};
\addplot [ 
    boxplot={draw position=3}, 
    color = blue
    ] table[x=x,col sep=comma] {Figures/csv/sphere.csv};
    
% delta Y
\addplot [mark = *, mark options = {red}, 
    boxplot={draw position=5}, 
    color = red
    ] table[x=y,col sep=comma] {Figures/csv/teapot.csv};
\addplot [ 
    boxplot={draw position=6}, 
    color = green
    ] table[x=y,col sep=comma] {Figures/csv/cube.csv};
\addplot [ 
    boxplot={draw position=7}, 
    color = blue
    ] table[x=y,col sep=comma] {Figures/csv/sphere.csv};
    
% delta Z  
\addplot [mark = *, mark options = {red}, 
    boxplot={draw position=9}, 
    color = red
    ] table[x=z,col sep=comma] {Figures/csv/teapot.csv};
\addplot [ 
    boxplot={draw position=10}, 
    color = green
    ] table[x=z,col sep=comma] {Figures/csv/cube.csv};
\addplot [ 
    boxplot={draw position=11}, 
    color = blue
    ] table[x=z,col sep=comma] {Figures/csv/sphere.csv};
 
% norm
\addplot [mark = *, mark options = {red}, 
    boxplot={draw position=13}, 
    color = red
    ] table[x=norm,col sep=comma] {Figures/csv/teapot.csv};
\addplot [ 
    boxplot={draw position=14}, 
    color = green
    ] table[x=norm,col sep=comma] {Figures/csv/cube.csv};
\addplot [ 
    boxplot={draw position=15}, 
    color = blue
    ] table[x=norm,col sep=comma] {Figures/csv/sphere.csv};  
\end{axis}
\end{tikzpicture}

我得到了这张图表: 在此处输入图片描述

我有 4 个相同的图表块。与 CSV 的 x 列相关的那个是正确的,但其他所有图表都只是从第一个块复制而来。

如何解决这个问题?

相关内容