This question is related to Plot Gantt-like plot from csv.
Consider the following file data.cvs
x,y
0,5
4,7
10,5
13,6
17,5
20,7
24,6
28,5
The second column represents some tasks (there are three in this example: 5,6, and 7) and the first column represents time. The table must be interpreted like this:
Each task "activates" from the corresponding value on the first column and extends to the value of the entry in the first column but on the following row. For example, task
5was active from0to4, from10to13, and from17to20; task6was active from13to17, and from24to28; task7was active from4to10, and from20to24.
The following code plots each task and shows when the task was "active":
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
x,y
0,5
4,7
10,5
13,6
17,5
20,7
24,6
28,5
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={5,6,7},
xtick=data
]
\addplot coordinates
{
(0,5) (4,5)
(4,7) (10,7)
(10,5) (13,5)
(13,6) (17,6)
(17,5) (20,5)
(20,7) (24,7)
(24,6) (28,6)
};
\end{axis}
\end{tikzpicture}
\end{document}
As you see, I introduced the coordinates manually; the idea is to do it automatically from the file data.csv.
I thought about using the datatool package, but I don't know how to access an element in the next row, not in the current one; schematically I'd use something like:
\documentclass[border=3pt]{standalone}
\usepackage{datatool}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\DTLloaddb[noheader=false]{coordinates}{data.csv}
\usepackage{filecontents}
\begin{filecontents*}{data.csv}
x,y
0,5
4,7
10,5
13,6
17,5
20,7
24,6
28,5
\end{filecontents*}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ytick={5,6,7},
xtick=data
]
%\DTLforeach*{coordinates}{\x=x,\y=y}{
% \addplot coordinates { (\x,\y) (???,\y) };
% }
\end{axis}
\end{tikzpicture}
\end{document}
where ???? stands for the element in the first column but in the next row to the current one. Can this be done?
Manually copying the first column makes the task easy, as I did in my answer to the linked question, but I'm looking for an automated way to do it.



