My data source contains lines with unplottable data. More precisely, the comma separated file reads like this for a few lines at the beginning:
0.0 , , , , , , , , ,
0.05, , , , , , , , ,
0.1 , , , , , , , , ,
0.15, , , , , , , , ,
0.2 , , , , , , , , ,
If I draw a diagram from this data, the data points (cirles) corresponding to these values, 0.0 ≤ x ≤ 0.2, are missing as they should.
However, the error bars are drawn in the wrong places. They should be missing for the same x values, and present for 0.25≤x≤1 (just like the points). Instead, they are instead drawn for 0.0≤x≤0.75. The error bars are shifted to the left by the number of empty rows in the data.
How can I get the error bars to still correspond to their data, even in the face of unplottable data in the input file?
Sidenote: Also the bars’ y position is off, but that can be fixed by specifying a y axis range of ymin=0, ymax=1
explicitly. I’ve left it out to make the example more minimal. Also the image looks cropped here, but that is not the problem, either, as the graph is trimmed to contain only the area in which plottable data occurs, namely 0.25 ≤ x ≤ 1
Expected Output
Here is an image of the output I seek to achieve. The circles from the picture above are represented by small horizontal lines in the image below.
The image also contains a bar graph and a left-hand ordinate, which are not of concern in this question (no problems with that – I left them out for brevity).Note that there is nothing plotted for x=0.2, neither a bar, nor a value (circle / horizontal line) nor an error bar.
MWE
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\newcommand{\file}{data.csv}
\begin{axis}[
table/col sep=comma,
width=10cm,
axis y line*=right,
]
\addplot [
only marks, red!100!black,
shift={(-4pt,0)},
error bars/.cd, y dir=both, y explicit]
table[
x={x},
y={5 y},
y error minus = {5 low err},
y error plus = {5 high err}
]{\file};
\addplot [only marks, green!70!black,
shift={(0,0)},
error bars/.cd, y dir=both, y explicit
]
table[
x={x},
y={7 y},
y error minus={7 low err},
y error plus ={7 high err}
]{\file};
\addplot [only marks, blue!100!white,
shift={(4pt,0)},
error bars/.cd,y dir=both, y explicit,
]
table[
x={x},
y={10 y},
y error minus = {10 low err},
y error plus ={10 high err},
]{\file};
\end{axis}
\end{tikzpicture}
\end{document}
Data File
The data is provided as comma separated values. The first column contains the x axis the rest is to be plotted against. Columns 4, 7, and 10 (‘5 y’, ‘7 y’, and ‘10 y’, respectively) contain the ‘actual’ data that is shown as circles in the first image and as short horizontal lines in the second.
Columns 2, 5, and 8 (‘5 low err’, ‘7 low err’, and ‘10 low err’, respectively) contain the lower bounds for the error bars. Columns 3, 6, and 9 (‘5 high err’, ‘7 high err’, and ‘10 high err’, respectively) contain the upper bounds for the error bars
The error bounds are given relative to the plotted ‘actual’ value. For instance, from line 7 we read: At x position 0.25 do not plot the series ‘5 y’ or its corresponding error bar; do plot the value 0.222 for series ‘7 y’, and an error bar from 0.222 to 0.222; do plot the value 0.146 (as circle) for series ‘10 y’, and an error bar from 0.146−0.014 (=0.132) to 0.146+0.0756 (=0.2216) relative to the plotted value.
data.csv:
x, 5 low err, 5 high err, 5 y, 7 low err, 7 high err, 7 y, 10 low err, 10 high err, 10 y
0,,,,,,,,,
0.05,,,,,,,,,
0.1,,,,,,,,,
0.15,,,,,,,,,
0.2,,,,,,,,,
0.25,,,,0,0,0.222,0.014,0.0756,0.146
0.3,,,,0.0012,0,0.223,0.031,0.0604,0.163
0.35,,,,0,0,0.222,0.0324,0.0572,0.165
0.4,,,,0.0012,0,0.223,0.0351,0.0562,0.167
0.45,0.0078,0.0001,0.312,0.0184,0.0924,0.219,0.0856,0.1201,0.192
0.5,0.2493,0.5171,0.458,0.2493,0.5171,0.458,0.2493,0.5171,0.458
0.55,0.2493,0.5171,0.458,0.2493,0.5171,0.458,0.2493,0.5171,0.458
0.6,0,0,0.975,0,0,0.975,0,0,0.975
0.65,0,0,0.975,0,0,0.975,0,0,0.975
0.7,0,0,0.975,0,0,0.975,0,0,0.975
0.75,0,0,0.975,0,0,0.975,0,0,0.975
0.8,0,0,0.975,0,0,0.975,0,0,0.975
0.85,0,0,0.975,0,0,0.975,0,0,0.975
0.9,0,0,0.975,0,0,0.975,0,0,0.975
0.95,0,0,0.975,0,0,0.975,0,0,0.975
1,0,0,0.975,0,0,0.975,0,0,0.975