Tikz 数据可视化:使用对数轴的误差线图

Tikz 数据可视化:使用对数轴的误差线图

我正在尝试使用 tikz 绘制一些带有误差线的数据。到目前为止,我成功地使用不同的可视化工具绘制了一个带有线性轴的示例。使用第 78.4 章“创建新的可视化工具”作为指南。我的代码的一个主要问题是,它不适用于对数轴。相反,它失败并出现错误“缺少数字”。

(没有画圆圈)我用下面的方法画了误差线:

\def\dovisualizationwitherror{%draw error in scale of coordinate system
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin}
    \pgfmathsetmacro{\uppererrorbracket}{\pgfkeysvalueof{/data point/y}+\pgfkeysvalueof{/data point/error}}
    \pgfmathsetmacro{\lowererrorbracket}{\pgfkeysvalueof{/data point/y}-\pgfkeysvalueof{/data point/error}}
    \path[Bracket-Bracket](visualization cs:x=\pgfkeysvalueof{/data point/x},y=\uppererrorbracket) -- %
                          (visualization cs:x=\pgfkeysvalueof{/data point/x},y=\lowererrorbracket);
    % \pgfusepath is done by |execute at end|
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end}
}

这是一个最小的工作示例。排除了对数轴。

\documentclass[tikz]{standalone}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{arrows.meta}


%Drawing method for errorbars
\newdimen\uppererrorbracket
\newdimen\lowererrorbracket

\def\dovisualizationwitherror{%draw error in scale of coordinate system
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at begin}
    \pgfmathsetmacro{\uppererrorbracket}{\pgfkeysvalueof{/data point/y}+\pgfkeysvalueof{/data point/error}}
    \pgfmathsetmacro{\lowererrorbracket}{\pgfkeysvalueof{/data point/y}-\pgfkeysvalueof{/data point/error}}
    \path[Bracket-Bracket](visualization cs:x=\pgfkeysvalueof{/data point/x},y=\uppererrorbracket) -- %
                          (visualization cs:x=\pgfkeysvalueof{/data point/x},y=\lowererrorbracket);
    % \pgfusepath is done by |execute at end|
    \pgfkeysvalueof{/data point/\pgfoovalueof{name}/execute at end}
}

%rest of classes for visualizer

\pgfooclass{errorbar visualizer}
{
    \attribute name;
    \method errorbar visualizer(#1) { \pgfooset{name}{#1} }
    \method default connects() {
            \pgfoothis.get handle(\me)
            \pgfkeysvalueof{/pgf/data visualization/obj}.connect(\me,visualize,visualize datapoint signal)
    }
    \method visualize() {
            \pgfdvfilterpassedtrue
            \pgfdvnamedvisualizerfilter
            \ifpgfdvfilterpassed
            \dovisualizationwitherror
            \fi
    }
}


\tikzdatavisualizationset{
    visualize as errorbar/.style={
            new object={
                    when=after survey,
                    store=/tikz/data visualization/visualizers/#1,
                    class=errorbar visualizer,
                    arg1=#1
            },
            new visualizer={#1}{%
                    color=visualizer color,
                    every path/.style={fill,draw},
            }{visualizer in legend=\tikz@dv@legend@entry@as@example},
            /data point/set=#1
    },
    visualize as errorbar/.default=errorbar
}


\begin{document}

\begin{tikzpicture}
    \datavisualization [
            scientific axes=clean,
            %y axis={logarithmic},
            visualize as errorbar,
    ]
    data{
            x, y, error
            0.1, 0.1, 0.2
            1, 1, 0.3
            1, 2, 0.3
            2, 0.1, 0.1
    };
\end{tikzpicture}

\end{document}

答案1

这不是你的可视化工具的问题,而是数学的问题。假设 y 值为 0.1,误差为 0.1,则意味着下限误差线为零。对数为零呢?对。因此,如果你确保误差小于 y 值,一切就都正常了。

相关内容