3

I am trying to plot my second plot in my thesis, and while the first one work (which is almost identical to the one I'm doing now) it won't work. Here's my code:

\begin{figure}[h]
\caption{something}
\label{blabla}
\begin{center}
\begin{tikzpicture}
\begin{axis}[width=12cm,height=6cm,
ylabel={Ugearet $\beta$},
xmin=2005, xmax=2016,
ymin=0.0, ymax=2.0,
xtick={2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016},
ytick={0.0,0.25,0.50,0.75,1.0,1.25,1.50,1.75},
xticklabel style={/pgf/number format/1000 sep=,rotate=60,anchor=east,font=\normalsize},
legend pos=north east,
ymajorgrids=true,
grid style=dashed,
] 

\addplot 
\draw [ultra thick, dotted, draw=red] 
    (axis cs: 2016,1.14) -- (axis cs: 2016,1.14)
    node[pos=0.5, above] {$y=12$};
\addplot[
color=blue,
mark=pentagon*,
]
coordinates {(2006,1.88)
(2007,0.76)
(2008,0.95)
(2009,0.75)
(2010,0.90)
(2011,0.80)
(2012,0.92)
(2013,0.74)
(2014,1.28)
(2015,1.36)
(2016,1.28)

};
\addlegendentry{Dansk bioteknologisk industri beta}    

\end{axis}
\end{tikzpicture}
\centering Kilde: 
\end{center}
\end{figure}

All I'm trying to do is to plot a horizontal line, with the average "beta" of 1.14. I did this in my previous plot (earlier in my thesis) but it won't let me do it now..

Any help is greatly appreciated!

Torbjørn T.
  • 206,688
Philip
  • 421

1 Answers1

2

You have two errors here. First, to draw your line you should simply say

\draw ... ;

and not \addplot \draw. Second, the line should be

\draw [ultra thick, dotted, draw=red] 
(axis cs: 2005,1.14) -- (axis cs: 2016,1.14)
node[pos=0.5, above] {$y=12$};

and not (2016,1.14) -- (2016,1.14) which is a point... and notice that since version 1.11 the axis cs: is assumed by default.

enter image description here

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • 1
    If the OP is using the latest pgfplots then (2016,1.14) and (axis cs: 2016,1.14) ought to be the same thing (if I'm not mistaken) – daleif Mar 21 '17 at 14:26
  • @daleif Yes, but that needs to be activated with \pgfplotsset{compat=1.11} (or higher). – Torbjørn T. Mar 21 '17 at 17:25
  • @TorbjørnT correct and isn't that recommended?. Btw wouldn't this look better with an equal number of digits on the Y axis? – daleif Mar 21 '17 at 17:28
  • @daleif Maybe, I don't know. Having an explicit compat setting might be recommended. – Torbjørn T. Mar 21 '17 at 17:31
  • @TorbjørnT or just compat=newest, not sure if there is an "at least this version" – daleif Mar 21 '17 at 17:32
  • 2
    @daleif No, that is not recommended (by Christian Feuersänger at least): http://tex.stackexchange.com/a/139695/586 – Torbjørn T. Mar 21 '17 at 17:34