# Plots with only a few (shifted) error bars

I want to make a figure with several plots with error bars. Each curve has 1100 points. I want to draw only a few (5) error bars to increase legibility. For the same reason, I would like to have each set of error bars shifted of a different interval. Something like :

plot 1 : error bars at 0, 250, 500, 750, 1000 ; plot 2 : error bars at 10, 260, 510, 760, 1010 ; plot 3 : error bars at 20, 270, 520 ,770, 1020 ; etc.

My current attempt is :

\pgfplotsset{err/.style={each nth point={250},forget plot,draw=none}}
\pgfplotsset{errp/.style={err, error bars/.cd,y dir=plus,  y explicit}}
\pgfplotsset{errm/.style={err, error bars/.cd,y dir=minus, y explicit}}

% plot 1
\addplot+[errm] table[x index=0,y index=1, y error index=2}]{\table};
\addplot+[errp] table[x index=0,y index=1, y error index=3}]{\table};

% plot 2
\addplot+[skip coords between index={0}{10}, errm] table[x index=0,y index=4, y error index=5}]{\table};
\addplot+[skip coords between index={0}{10}, errp] table[x index=0,y index=4, y error index=6}]{\table};

% plot 3
\addplot+[skip coords between index={0}{20}, errm] table[x index=0,y index=7, y error index=8}]{\table};
\addplot+[skip coords between index={0}{20}, errp] table[x index=0,y index7, y error index=9}]{\table};

% etc.


The each nth point={250} acts as I want but skip coords between index={0}{20} does not (it only suppress the first error bar).

In addition, compilation time is tremendous and I wonder if changing somehow my method could diminish it (I already use externalisation). My other attempt was to generate a table for the errors containing only the relevant data and plot them all. This is somewhat more cumbersome because it requires to go back to the generation of data each time one wants to alter how the plot looks.

To sum up:

• how to introduce the skip ?
• Is there a more concise and efficient code to do that ?

Some data:

full.dat

First column is abscissa. Then 3 column of data. Then 3 column minus error. Then 3 column plus error.

The example:

expl.tex is the main, graph.tex is the figure.

expl.tex

graph.tex

-
Could you provide some dummy data and a minimal example document (starting from \documentclass)? Coming up with dummy data and a framework document is always the dullest part of answering a question, so it would be great if not every person trying to come up with an answer would have to go through that. –  Jake Apr 25 '12 at 8:18
Do your plots overlap much? Maybe plotting error bounds (or areas) instead of error bars might be a clearer way of conveying the information. –  Jake Apr 25 '12 at 8:22
They do overlap a lot. I'll provide data. –  Alfred M. Apr 25 '12 at 8:25

You could use

\addplot [draw=none, forget plot]
gnuplot [raw gnuplot] {plot "full.dat" using 1:2:5:8 every 300::50 with yerrorbars};


to make gnuplot write columns 1, 2, 5 and 8 of every 300th line starting from line 50 to a file called \jobname.pgf-plot.table. This can then be used in your error bar plotting commands. Gnuplot is very fast at downsampling the files, much much faster than the each nth point key.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\pgfplotsset{err/.style={forget plot,draw=none}}
\pgfplotsset{errp/.style={err, error bars/.cd,y dir=plus,  y explicit}}
\pgfplotsset{errm/.style={err, error bars/.cd,y dir=minus, y explicit}}
\begin{axis}[
/pgfplots/table/header=false % This is necessary, otherwise the first line of each file would be assumed to not contain data, but the column names
]

\addplot [draw=none, forget plot] gnuplot [raw gnuplot] {plot "full.dat" using 1:2:5:8 every 300 with yerrorbars};
\addplot +[no markers] table [y index=1]{\table};

\addplot [draw=none, forget plot] gnuplot [raw gnuplot] {plot "full.dat" using 1:3:6:9 every 300::50 with yerrorbars};

Regarding the option /pgfplots/table/header=false ; I never used it but the first line of my tables are taken into acount. Is your remark specific to the use of gnuplot ? –  Alfred M. Apr 30 '12 at 9:02
@AlfredM.: pgfplots assumes that the first row contains the column names if there's at least one non-numeric character. Gnuplot saves its results in exponential notation, so there are a couple of es in there, that's why you need to use header=false here. –  Jake Apr 30 '12 at 9:10