等距轴和异常值处理

等距轴和异常值处理

你好,我是 Latex 的新手,我正在尝试在 x 的等空间值中绘制一些数据,到目前为止我已经完成了以下操作:

\begin{tikzpicture}
    \begin{axis}[
        ybar,
        bar width=7pt,
        xtick distance=2,
        xlabel=pH,
        xtick=\empty,
        extra x ticks={3.0,3.8,5.2,7.5,10},
        extra x tick labels={3.0,3.8,5.2,7.5,10}]
        ylabel=Size (d.nm),
        enlarge x limits={abs=0.5},

        ymin=0,
        scaled ticks=false,

        xtick style={
            /pgfplots/major tick length=0pt,
        },
    ]
        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (10,15.23)+-(10,0.0346410161513768)
            (7.5,16.8466666666667)+-(7.5,0.14224392195568)
            (5.2,18.1166666666667)+-(5.2,0.187705443004015)
            (3.8,18.6866666666667)+-(3.8,0.14571661996263)
            (3,18.4033333333333)+-(3,0.117189305541646)
        };

        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (10,17.66)+-(10,0.174355957741627)
            (7.5,15.4966666666667)+-(7.5,0.0251661147842353)
            (5.2,18.5066666666667)+-(5.2,0.173877351409934)
            (3.8,18.18)+-(3.8,0.0871779788708136)
            (3,18.4966666666667)+-(3,0.0776745346515396)
        };
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (10,19.01)+-(10,0.156204993518134)
(7.5,18.7266666666667)+-(7.5,0.11503622617825)
(5.2,19.07)+-(5.2,0.112694276695846)
(3.8,18.39)+-(3.8,0.0871779788708136)
(3,18.7233333333333)+-(3,0.11503622617825)
        };
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (10,19.5)+-(10,0.219317121994613)
(7.5,18.6933333333333)+-(7.5,0.0602771377334176)
(5.2,19.2866666666667)+-(5.2,0.0251661147842344)
(3.8,19.4766666666667)+-(3.8,0.0680685928555417)
(3,19.1866666666667)+-(3,0.0404145188432747)
        };
\addplot+ [
            error bars/.cd,
                y dir=plus,
                y explicit relative,
        ] coordinates {
            (10,65)+-(10,8)
(7.5,64.5633333333333)+-(7.5,4.27418218298347)
(5.2,68.3033333333333)+-(5.2,0.733303029676911)
(3.8,68.02)+-(3.8,0.347706773014274)
(3,72)+-(3,2.80770962411239)
        };
    \end{axis}
\end{tikzpicture}

但空格间距并不像我在 Excel 中那样均匀在此处输入图片描述。另外,您知道处理异常值条的任何方法吗?或者最好是绘制两个图,然后将异常值排除在外。

感谢您的帮助

答案1

您可以使用symbolic x coords它来创建类似于 excel 输出的内容。pH=10 组的误差线非常大。我暂时抑制了它们。在我看来,要么y explicit relative是错误的,要么是误差太大。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[width=12cm,
        ybar,
        bar width=7pt,
        xlabel=pH,
        symbolic x coords={A,B,C,D,E},
        xtick={A,B,C,D,E},
        xticklabels={10,7.5,5.2,3.8,3.0},
        ylabel=Size (d.nm),
        enlarge x limits={0.2},
        ymin=0,
        scaled ticks=false,
        xtick style={
            /pgfplots/major tick length=0pt,
        }
    ]
        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (A,15.23)+-(A,0.0346410161513768)
            (B,16.8466666666667)+-(B,0.14224392195568)
            (C,18.1166666666667)+-(C,0.187705443004015)
            (D,18.6866666666667)+-(D,0.14571661996263)
            (E,18.4033333333333)+-(E,0.117189305541646)
        };

        \addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (A,17.66)+-(A,0.174355957741627)
            (B,15.4966666666667)+-(B,0.0251661147842353)
            (C,18.5066666666667)+-(C,0.173877351409934)
            (D,18.18)+-(D,0.0871779788708136)
            (E,18.4966666666667)+-(E,0.0776745346515396)
        };
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (A,19.01)+-(A,0.156204993518134)
            (B,18.7266666666667)+-(B,0.11503622617825)
            (C,19.07)+-(C,0.112694276695846)
            (D,18.39)+-(D,0.0871779788708136)
            (E,18.7233333333333)+-(E,0.11503622617825)
        };
\addplot+ [
            error bars/.cd,
                y dir=both,
                y explicit relative,
        ] coordinates {
            (A,19.5)+-(A,0.219317121994613)
            (B,18.6933333333333)+-(B,0.0602771377334176)
            (C,19.2866666666667)+-(C,0.0251661147842344)
            (D,19.4766666666667)+-(D,0.0680685928555417)
            (E,19.1866666666667)+-(E,0.0404145188432747)
        };
\addplot+ [
            error bars/.cd,
                y dir=plus,
                %y explicit relative,
        ] coordinates {
            (A,65)+-(A,8)
            (B,64.5633333333333)+-(B,4.27418218298347)
            (C,68.3033333333333)+-(C,0.733303029676911)
            (D,68.02)+-(D,0.347706773014274)
            (E,72)+-(E,2.80770962411239)
        };
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容