5

I am trying to plot a Gantt-like chart with pgfplot from a CSV-File. The aim is to display the behavoir of a task scheduler. In my CSV-File I have tupel of timestamp(x) and task ID(y).

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{data.csv}
x,y
8868932,10
8868949,9
8868985,10
8868995,34
8869924,4
8869969,10
8869987,9
8870023,10
8870033,18
8870043,34
8870915,1
8870949,4
8871062,10
8871079,9
8871115,10
8871125,23
8871147,34
8871890,4
8871920,10
8871937,9
8871973,10
8871983,26
8872878,10
8872896,9
8872932,10
8872941,11
8872980,26
8873862,10
8873879,9
8873915,10
8873925,18
8873935,26
8874281,34
8874632,26
\end{filecontents}
\begin{document}
\begin{figure}
\begin{tikzpicture}[
  font=\sffamily \footnotesize
]
\begin{axis}[
    grid = major,
    scaled ticks=false,
    symbolic y coords={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34},
ytick={1,...,34},
height=12cm,
width=15cm,
x tick label style={rotate=90,anchor=east},
]
\addplot[
        only marks,
        mark=square, 
        scatter,
    ] table [x=x, y=y, col sep=comma] {data.csv};

\end{axis}

\end{tikzpicture}
\end{figure}
\end{document}

Every data point indicates which task was active. But instead to show only the point the task was scheduled I like to display the period of time the task was active. So the mark at each point needs to have a width relative to the differnce of the next timestamp and this timestamp. Is there any possibility to do this with pgfplot? Or do you have any other idea to display a gantt-like chart with this given data?

Thank you very much

  • I still don't quite understand the intended result. Could you please explain in more detail? For example, given these 8868932,10 8868949,9 8868985,10 8868995,34 8869924,4 8869969,10 six rows in your data table, what would be the expected outcome? – Gonzalo Medina Sep 6 '15 at 22:20
  • Just to clarify, what I don't fully understand is how the width for the bars is calculated. – Gonzalo Medina Sep 6 '15 at 22:26
  • Hello Gonzalo, the width for the first dataset will be 8868949 - 8868932 = 17. So Task-ID 10 was 17 ticks active. And 17 should be the width of the bar. The width of the next tuple will be 8868985 - 8868949 = 36 which is the number of ticks for Task 9 and so on. – HarryHaller86 Sep 6 '15 at 22:30
  • I've updated my answer with a simplified solution. – Gonzalo Medina Sep 8 '15 at 1:19
1

Here's one option using the jump mark left plot (a variant of const plot without lines); one problem is that the some of the widths will be too short compared to the data, so even with a 30cm width plot some of the intervals are difficult to see:

\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.12}

\usepackage{filecontents}
\begin{filecontents}{data.csv}
x,y
8868932,10
8868949,9
8868985,10
8868995,34
8869924,4
8869969,10
8869987,9
8870023,10
8870033,18
8870043,34
8870915,1
8870949,4
8871062,10
8871079,9
8871115,10
8871125,23
8871147,34
8871890,4
8871920,10
8871937,9
8871973,10
8871983,26
8872878,10
8872896,9
8872932,10
8872941,11
8872980,26
8873862,10
8873879,9
8873915,10
8873925,18
8873935,26
8874281,34
8874632,26
\end{filecontents}

\begin{document}

\begin{tikzpicture}[
  font=\sffamily \footnotesize
]
\begin{axis}[
  grid = major,
  scaled ticks=false,
  thick,
  ytick={1,...,34},
  height=12cm,
  width=30cm,
  x tick label style={rotate=90,anchor=east},
]
\addplot+[jump mark left] table[col sep=comma]{data.csv};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Thanks to skevin93 for his answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.