Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible, and if yes how, to plot a table with pgfplots where the marks are ellipses with the major and minor semiaxes being the size of the error? Such that a data point is displayed as its own "area of uncertainty". Fading-out towards the edges of the ellipses would be a nice plus but is purely optional.

Unfortunately I can't provide an "already-tried-it-this-way example", because I have absolutely no idea where to start here.

share|improve this question
    
If you could provide us with a drawing of what you want to achieve it would be easier to understand what your are trying to achieve. –  DrJay Nov 21 '12 at 8:15

1 Answer 1

up vote 5 down vote accepted

You can use the existing error bar infrastructure to place coordinates at the end points of the major and minor axes of the error ellipses, and then draw the ellipse using a simplified version of Percusse's answer to How to fit ellipse into another object - using intersections and calc library.

Here's an error ellipse style that does this. You can change the style of the error ellipse using the key error ellipse style. To get a faded filling, you could set error ellipse style={inner color=red, outer color=white}.

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, filecontents}
\usetikzlibrary{calc}

\pgfplotsset{compat=1.5.1}
\newcounter{mark}
\pgfplotsset{
    every error ellipse/.style=draw,
    error ellipse style/.style={
        every error ellipse/.style={#1}
    },
    error ellipse/.style={
        error bars/error mark options={},
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \stepcounter{mark}
            \coordinate [inner sep=0pt] (errormarknode-\themark) at ##2 {};
            \ifnum\themark=4
                \path [/pgfplots/every error ellipse] let
                    \p1=(errormarknode-1),
                    \p2=(errormarknode-2),
                    \p3=(errormarknode-3),
                    \p4=(errormarknode-4)
                in
                    ##1 ellipse [x radius=(\x2-\x1)/2, y radius=(\y4-\y3)/2]
                ;
                \setcounter{mark}{0}
            \fi
        }
    }
}


\begin{filecontents}{data.dat}
x y errorx errory
1 1 0.1 0.2
3 2 1 0.3
5 2 1 1
\end{filecontents}


\begin{document}

\begin{tikzpicture}
\begin{axis}[
    grid=both,
    axis equal % So equal x and y errors result in circles
]
\addplot [
    mark=*, only marks,
    error ellipse,
    error bars/.cd,
        x dir=both, y dir=both,
        x explicit, y explicit
] table [
    x error=errorx, y error=errory
] {data.dat};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
    
Wow, nice. Thanks. :) Is it possible to remove the dots in the ellipses? –  Foo Bar Nov 21 '12 at 17:23
1  
@FooBar: Sure, they're just the normal plot marks which don't have anything to do with the error ellipses. Just set no markers, draw=none in the \addplot options instead of only marks, and the dots disappear. –  Jake Nov 21 '12 at 18:35
    
Where would I have to set the style with the inner and outer color for the fading? I tried putting it everywhere, but it just don't gets displayed... –  Foo Bar Nov 22 '12 at 10:20
1  
@FooBar: You just put error ellipse style={inner color=red, outer color=white} straight after error ellipse in the \addplot options. –  Jake Nov 22 '12 at 10:22
1  
@FooBar: Thanks! By the way, you can also put the error ellipse style={inner color=red, outer color=white} in the axis options if you want the same style for all plots, or you can set it gobally using \pgfplotsset{error ellipse style={inner color=red, outer color=white}} anywhere in your document before the axis. –  Jake Nov 22 '12 at 12:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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