Pgfplots:读取带有全局 y 误差表达式的表格

Pgfplots:读取带有全局 y 误差表达式的表格

我正在绘制几条带误差线的曲线。原则上,我使用如下代码进行操作(当然,表格通常是从文件中读取的):

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.13,
    error bars/y explicit,
    error bars/error bar style={solid},
}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
            error bars/y dir=both,
        ]
        \addplot table [y error expr=sqrt(\thisrowno{2})] {
            0       0       0
            1       1       0.9
            2       4       0.9
            3       9       1.6
        };
    \end{axis}
\end{tikzpicture}
\end{document}

MWE 的样子。

但是,我有很多不想y error expr每次都重复的图。因此,我尝试将本地语句移至全局axis

[...]
    \begin{axis}[
            error bars/y dir=both,
            table/y error expr=sqrt(\thisrowno{2}),    % <-- added
        ]
        \addplot table {
[...]

不幸的是,这会导致以下错误:

Package pgfkeys Error: I do not know the key '/tikz/y error plus expr',
to which you passed 'sqrt(\thisrowno {2})', and I am going to ignore it.
Perhaps you misspelled it.
Package pgfkeys Error: I do not know the key '/tikz/y error minus expr',
to which you passed 'sqrt(\thisrowno {2})', and I am going to ignore it.
Perhaps you misspelled it.

y error expr我怎样才能对所有s做出单一陈述table

答案1

我会将此视为一个错误。请查看代码中的注释以找到解决方法。

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        error bars/y explicit,
        error bars/error bar style={solid},
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        error bars/y dir=both,
        % -----------------------------------------------------------------
%        % because the following line is causing an error ...
%        table/y error expr=sqrt(\thisrowno{2}),
        % ... we can use the following two lines to make it work
        table/y error plus expr=sqrt(\thisrowno{2}),
        table/y error minus expr=sqrt(\thisrowno{2}),
        % -----------------------------------------------------------------
    ]
        \addplot table {
            0       0       0
            1       1       0.1
            2       4       0.2
            3       9       1.6
        };
        \addplot table {
            0       1       0
            1       2       0.9
            2       5       0.9
            3      10       1.6
        };
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容