5

How can I plot data points with pgfplots that have no marks, but error bars? If I try marks=none and enable errobars, I get big filled circles with errobars. If I change my mark to mark=+, for example, I have to adjust the mark size by hand, so that the errorbars are bigger than the mark.

The reason is, if I have error bars, I automatically have the actual data point: the point where the error bars cross. So I don't need an explicit mark , but as described, just setting mark=none doesn't seem to be enough to achieve this.

This plots filled circles with error bars as marks even mark=none is set:

\begin{tikzpicture}
  \begin{axis}
    \addplot[ only marks, mark=none,
              error bars/.cd, y dir=both, x dir=both, x explicit, y explicit]
       table [x index=0, y index=2, x error index=1, y error index=3]
       {mydata.txt};
  \end{axis}
\end{tikzpicture}

Part of the content of mydata.txt to work with:

3.414   8E-3    3.62    5E-2
1.570   2E-2    1.65    1E-1
3.809   9E-3    3.96    3E-2
4.340   2E-2    4.34    3E-2

How do I get error bars without an actual mark symbol, so that the point is "auto-marked" by the crossing of the error bars?

  • 1
    Could you include an MWE? – Sean Allred Mar 29 '13 at 12:24
  • Done. Hope this is enough. – Foo Bar Mar 29 '13 at 12:34
  • Sorry for replying late - internet is a little shoddy - but what exactly is in mydata.txt? (filecontents is a great environment if you're unaware ;)) – Sean Allred Mar 29 '13 at 13:08
  • I added a part of the data to work with. – Foo Bar Mar 29 '13 at 13:15
  • 1
    Yes, scatter plot seems to be the right term (English is not my native language). I want these (x+-dx, y+-dy) value pairs plotted (with errobars, but with marks and without "connecting lines"). – Foo Bar Mar 29 '13 at 13:29
7

Add the no markers option to the axis, and then supply scatter, only marks to the plot. Seems paradoxical, but it works:

\documentclass{article}
\usepackage{tikz,pgfplots,filecontents}
\begin{filecontents*}{mydata.txt}
3.414   8E-3    3.62    5E-2
1.570   2E-2    1.65    1E-1
3.809   9E-3    3.96    3E-2
4.340   2E-2    4.34    3E-2
\end{filecontents*}

\pgfplotsset{compat=1.7}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[no markers]
    \addplot[scatter, only marks,
              error bars/.cd, 
              y dir=both, x dir=both,
              x explicit, y explicit]
       table [x index=0, y index=2, x error index=1, y error index=3]
       {mydata.txt};
  \end{axis}
\end{tikzpicture}
\end{document}

Output:

output

  • Thanks for the analysis. It should have worked to write only marks,mark=none. I will note this on the bug list for pgfplots to fix it eventually. – Christian Feuersänger Mar 29 '13 at 15:48
  • Thanks, Christian! Yeah, it's weird that it doesn't work like that, but it may have something to do with mark=none resetting all other options (it said something about this in the documentation). – Sean Allred Mar 29 '13 at 15:50
  • This works fine for the plot, but how to create a legend for this plot. Using \addlegendentry{data1} will not produce any legend marker as no markers or lines are plotted for this data. – Janek Aug 26 '14 at 12:07
  • @Janek well, what would you expect? I've personally no idea what a legend would look like for a plot such as this. – Sean Allred Aug 26 '14 at 12:31
  • In principle, I would expect some sort of + with T ends. I want to plot several datasets in one plot using different colors to distinguish them from each other. The legend would then have the same markers but different colors for each entry. – Janek Aug 26 '14 at 12:52

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.