1

I'm trying to plot some data with errorbars using tikz. So far i'm successful plotting a examples with linear axis using a different visualizer. Used chapter 78.4 "Creating New Visualizers" as guideline. The one major problem with my code is, it won't work with logarithmic axis. Instead it fails with error "missing number".

(Instead of drawing circles ) I've drawn errorbars with following method:

\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}
}

Here is a minimal working example. Excluded the logarithmic axis.

\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

This is not a problem with your visualizer, but with mathematics. Considering a y-value of 0.1 and an error of 0.1, means that the lower error bar would be at zero. And a logarithm of zero is? Right. So therefore, if you ensure that your error is less than your y-value everything works.

|improve this answer|||||
  • also an error bar doesn't make visually any sense in log scale – percusse Oct 2 '16 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.