pgfplots: Showing points as just error bars

Presenting experimental work in a clear form is an important skill. For plotting data, I like the excellent pgfplots package, which makes it easy to put together consistent presentations of complex data. At the moment, I’d doing some experiments where showing the error bars on the raw data is important, but at the same time to show fit lines clearly. The best style I’ve seen for this is one where the data are show as simple vertical bars which have length determined by the error bars for the measurements. The fit lines then stand out clearly without overcrowding the plot. That style isn’t built in to pgfplots but it’s easy to set up with a little work:

\documentclass{standalone}
\usepackage{pgfplots}

% Use features from current release
\pgfplotsset{compat = 1.12}

% Error 'sticks'
\pgfplotsset{
  error bars/error mark options = {draw = none}
  % OR more low-level
  % error bars/draw error bar/.code 2 args = {\draw #1 -- #2;} 
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    [
      error bars/y dir      = both,
      error bars/y explicit = true,
    ]
    \addplot[draw = none] table[y error index = 2]
      {
        0   0.023 0.204
        1   0.956 0.332
        2   4.234 0.552
        3   8.764 0.345
        4  17.025 0.943
        5  27.201 2.445
      };
    \addplot[color = red, domain = 0:5, samples = 100] {x^2};
  \end{axis}
\end{tikzpicture}
\end{document}

Demo
My demo only has a few data points, but this style really shows it’s worth as the number of points rises.

A place for (PGF) plot examples

Not content with running The LaTeX Community, TeXample and texdoc.net, blogging on TeX matters and being a moderator on TeX Stack Exchange, Stefan Kottwitz has now started a new site: pgfplots.net. The idea for the new site is simple: it’s a place to collect great examples of plots, (primarily) made using using the excellent pgfplots package. Why do this? Plots are just graphics, but they are a very special form of graphic with particular requirements. As a working scientist, I really appreciate the need for well-presented, carefully-constructed plots: they can make (or break) a paper.

At the moment, the selection of plots is of course quite small: the site is new and the room for ‘artistic’ work is perhaps a little more limited than in the TeXample gallery. I’m sure it will soon grow, and we can all pick up a trick or two! (Don’t worry: there will certainly be a few plots for chemists. Indeed, you might already spot some.)

Real life pgfplots examples

I’ve just sent a draft to TUGBoat for an article about pgfplots. As many readers will know, pgfplots is built on pgf/Tikz, which means that it can be used for both DVI and PDF output, and with plain TeX, LaTeX and ConTeXt. In my draft, I’ve used some real life plots (from a couple of recent publications in the research group I work in). The draft will probably change a bit, but for a preview take a look a the the PDF.

pgfplots v1.3

A new version of the very useful pgfplots package has been released. pgfplots provides a very handy interface on top of pgf/TikZ to generate print-quality plots without too much effort. As many readers will know, pgf works with both DVI and PDF output methods, making pgfplots very handy for generating plots without worrying about other content.

For me, the stand-out new feature in v1.3 of pgfplots is the ability to automatically reverse the axes. As a chemist, I need to do this as convention dictates that some types of data are displayed with the x axis running from high values to low ones. So for me not having to do this by hand is a really significant reason to upgrade. There are lots of other new features as well: I see that the manual now includes a number of 3D surface style graphs, which many people like.

If you are plotting data in TeX, the pgfplots should be very high on your list of packages to consider.