5

I'like to add an vertical line with some text in a graphic, but i've not found the way.

I tried something like

\addplot coordinates { (2008-01-01,0)  (2008-01-01,130)} node {some text};

but it didnt work and i'm stuck

Here is a working minimal example, that creates first the ybar stacked

\documentclass{standalone}              
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}

\begin{document}

\pgfplotstableread[col sep=comma,header=true]{
Year,1,1.1,1.2,1.3,1.4
2005,0,0.29,21.97,42.22,27.98
2006,0,1.43,8.25,47.53,29.96
2007,0.05,0.05,13.62,45.26,34.05
2008,0.06,0.89,10.63,30.84,44.63
2009,0.09,0,7.71,30.82,46.75
2010,0,0,1.65,28.34,27.02
2011,0,0,0.94,29.02,7.64
}\data

\begin{tikzpicture}     
    \begin{axis}[
            stack plots=y,
            area style,                  
            enlarge x limits=false,
            enlarge y limits=upper,                     
            x tick label style={/pgf/number format/1000 sep=},      
    ymax=150
        ]
        \addplot table [x=Year, y=1] {\data} \closedcycle;
        \addplot table [x=Year, y=1.1] {\data} \closedcycle;             
        \addplot table [x=Year, y=1.2] {\data} \closedcycle;
        \addplot table [x=Year, y=1.3] {\data} \closedcycle;
        \addplot table [x=Year, y=1.4] {\data} \closedcycle;     
        \end{axis}
\end{tikzpicture}


\end{document}
5
  • If I understand correctly, this has nothing to do with the filled area or the dateplot library (you're loading, but not using the latter). You're basically asking: How can I add a vertical line and a text label to a PGFPlots plot, right?
    – Jake
    Commented Dec 2, 2013 at 17:14
  • 3
    If the answer to @Jakes question is yes, than someting like \node [coordinate, pin=above:{Some text}] at (axis cs:2008,130) {}; could be of help. pgfplots gives you the possibility to add nodes relatively to a coordinate system (cs) axis.
    – Johannes_B
    Commented Dec 2, 2013 at 17:17
  • yes Jake you're right
    – gVermandel
    Commented Dec 2, 2013 at 17:23
  • I've just tested your idea Johannes_B and it works, thanks a lot !
    – gVermandel
    Commented Dec 2, 2013 at 17:24
  • @gVermandel I updated my comment to an answer. If this is helping you, you can accept it.
    – Johannes_B
    Commented Dec 2, 2013 at 19:38

1 Answer 1

5

You can enter the coordinate system (cs) of an axis using axis cs. You should use this, whenever you want to add something to a plot, because pgfplots takes care of appropriate data scaling, logarithms, and even symbolic x coords. Have a look at the following, this might give you a good starting point.

\documentclass{standalone}              
\usepackage{pgfplots}
%\usepgfplotslibrary{dateplot}

\begin{document}

\pgfplotstableread[col sep=comma,header=true]{
Year,1,1.1,1.2,1.3,1.4
2005,0,0.29,21.97,42.22,27.98
2006,0,1.43,8.25,47.53,29.96
2007,0.05,0.05,13.62,45.26,34.05
2008,0.06,0.89,10.63,30.84,44.63
2009,0.09,0,7.71,30.82,46.75
2010,0,0,1.65,28.34,27.02
2011,0,0,0.94,29.02,7.64
}\data

\begin{tikzpicture}     
    \begin{axis}[
            stack plots=y,
            area style,                  
            enlarge x limits=false,
            enlarge y limits=upper,                     
            x tick label style={/pgf/number format/1000 sep=},      
    ymax=150
        ]
        \addplot table [x=Year, y=1] {\data} \closedcycle;
        \addplot table [x=Year, y=1.1] {\data} \closedcycle;             
        \addplot table [x=Year, y=1.2] {\data} \closedcycle;
        \addplot table [x=Year, y=1.3] {\data} \closedcycle;
        \addplot table [x=Year, y=1.4] {\data} \closedcycle;  
        \draw (axis cs:2006,0) -- (axis cs:2006,130) node [above] {Some text};
        \node [coordinate, pin=above:{Some other text}] at (axis cs:2008,130) {};
        \draw (axis cs:2010,0) |- (axis cs:2009,110) node [left] {Some more text};
        \end{axis}
\end{tikzpicture}
\end{document}

You can find more information in the documentation of pgfplots.

Result:

result

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .