I am using this macro
\newcommand{\ymax}[0]{\pgfkeysvalueof{/pgfplots/ymax}}
to do stuff like the following:
\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, \ymax);
and this works fine.
However, if I want to do something like \ymax / 2 or 0.5 * \ymax, this doesn't work. I get the error, "Could not parse input ' 0.5 * 1.09763666e6' as a floating point number, sorry."
Do I need to use something like \pgfmathparse? What is the correct way to do arithmetic on this value?
When I change the expression to
\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, \pgfmathparse{0.5*\ymax});
then my TeX Live freezes and I have to ^C out.
MWE
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[enlargelimits=false]
\newcommand{\getpgfkey}[1]{\pgfkeysvalueof{/pgfplots/#1}}
\newcommand{\ymax}[0]{\getpgfkey{ymax}}
\newcommand{\ymin}[0]{\getpgfkey{ymin}}
\addplot [smooth, domain=0:6] (x, x); % to generate an axis cs
% this works fine
\draw[dashed] (axis cs:2, \ymin) -- (axis cs:2, \ymax);
% none of these work
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, \ymax / 2);
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, (\ymax / 2));
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, ({\ymax / 2}));
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, {(\ymax / 2)});
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, (0.5*\ymax));
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, (0.5*{\ymax}));
%\draw[dashed] (axis cs:4, \ymin) -- (axis cs:4, {0.5*(\ymax});
\end{axis}
\end{tikzpicture}
\end{document}
The error I get is:
! Package PGF Math Error: Could not parse input ' {0.5*6.0e0}' as a floating po
int number, sorry. The unreadable part was near '*6.0e0'..
See the PGF Math package documentation for explanation.
Type H <return> for immediate help.

at (axis cs:4, ({\ymax / 2}))I getCould not parse input ' ({3.3075714e6/ 2}'; is the lack of space betweene6and/contributing to the problem? – wchargin Jan 30 '14 at 00:03at (axis cs:4,{(\ymax / 2)})still yieldsCould not parse input '(3.3075714e6/ 2)'as a floating point number... am I missing something? – wchargin Jan 30 '14 at 00:14\pgfplotsset{compat=1.8}; could you share your test document? – wchargin Feb 02 '14 at 18:41