1

I'm trying to replicate the following using tikz and/or pgfplots:

Segments with time points

I've tried to adapt the code from ybar stacked plot with negative coordinates, but the bars seem to be bound to the axes (i.e., I wasn't able to output anything like the red segment in the diagram).

Your help is much appreciated!

Edit: Added sample code. I would like the bottom orange segment (at -4) to disappear, and to be able to add dashed vertical lines.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        xbar stacked,
        bar width=10pt,
        axis lines*=middle,
        axis on top=false,
        after end axis/.code={
            \node at ({rel axis cs:0,0}|-{axis cs:0,0}) [anchor=east] {0};
        }
    ]
      \addplot[
        fill=cyan,
        draw=none,
        bar shift=-8pt,
        mark options={
            gray,
            thick,
            dashed
        },
        mark=waterfall bridge
      ] coordinates { (1, 3) (2, 3) (3,3) (4,3) };
      \addplot[
        fill=orange,
        draw=none,
        bar shift=8pt
      ] coordinates { (1,-4) (2,-4) (3,4) (4,4) };
    \end{axis}
  \end{tikzpicture}

  \end{document}
\end{filecontents*}
  • Welcome to TeX.SE. It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem, and shows what you have tried.

    While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem.

    – Peter Grill Feb 20 '14 at 18:49

1 Answers1

2

Using TiKz, an output may be as follow with this code:

 \documentclass{standalone}
    \usepackage{tikz}

    \begin{document}
    \begin{tikzpicture}

  \node at (0,0) [draw, rectangle, fill=blue!20, minimum height=0.5cm, minimum width=5cm] (rect1) {};
    \node at (2.5,-1)[draw, rectangle, fill=red, minimum height=0.5cm, minimum width=4cm] (rect2) {};
    \draw [ dashed,red] (rect2.west)--++(90:1.25);
    \draw [ dashed, red] (rect2.north)--(rect1.east);
    \foreach \x/\alp in {-1.25/A,1.5/B,3.5/C,5.5/(a)}{
    \node at (\x,-0.5) {\small \alp};}
    \foreach \x/\alp in {-2.5/T1,0.5/T2,2.5/T3,5/T4}{
    \node at (\x,-1.75) {\small \alp};}

     \node at (1,-4) [draw, rectangle, fill=blue!20, minimum height=0.5cm, minimum width=7cm] (rect3) {};
     \foreach \x/\alp in {-1.25/A,1.5/A,3.5/A}{
     \node at (\x,-3.25) {\small \alp};}

      \foreach \x/\alp in {-2.5/T1,0.075/T2,2.5/T3,4.5/T4}{
    \node at (\x,-4.75) {\small \alp};}
    \node at (5.5,-4) {\small (b)};
   % \filldraw (
    \draw [dashed] (0,-4.25)--++(90:1.5);
    \draw [dashed] (2.5,-4.25)--++(90:1.5);
    ![enter image description here][1]
\end{tikzpicture} 

\end{document}

Output:

enter image description here