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.

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};
\addplot table[x index=0,y index=1]{\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};
\addplot table[x index=0,y index=4]{\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};
\addplot table[x index=0,y index=7]{\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

share|improve this question
    
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
add comment

1 Answer

up vote 4 down vote accepted

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}

\pgfplotstableread{full.dat}{\table}

\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+[errm] table [y error index=2]{\jobname.pgf-plot.table};
\addplot+[errp] table [y error index=3]{\jobname.pgf-plot.table};
\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};
\addplot+[errm] table [y error index=2]{\jobname.pgf-plot.table};
\addplot+[errp] table [y error index=3]{\jobname.pgf-plot.table};
\addplot +[no markers] table [y index=2]{\table};

\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
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
1  
@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
    
I tried removing the option with data written in scientific notation. The first data is taken into account. It seems that pgfplots understand scientific notation. –  Alfred M. Apr 30 '12 at 11:48
add comment

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.