To continue my question here now I'd like to understand how to use ymax, ymin etc. values in new variables made with pgfmathparse or pgfmathsetmacro. So, if I know \pgfkeysvalueof{/pgfplots/ymax} and \pgfkeysvalueof{/pgfplots/ymin} how to set new variable \eh being (ymax - ymin)/10? This code:
\pgfmathsetmacro{\eh}{0.1*\pgfkeysvalueof{/pgfplots/ymax} -0.1*\pgfkeysvalueof{/pgfplots/ymin}}
gives the error message: Missing number, treated as zero. I'd like to use this \eh as a height of rectangle or in other calculations of coordinates.
EDIT:
Added MWE as asked.
\documentclass{article}
\usepackage{pgfplots}
\usepackage{siunitx}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\pgfkeys{
/pgf/number format/precision=1,
/pgf/number format/fixed zerofill=true }
\begin{axis}[
xmin=1,
xmax=4,
grid=both,
clip=false
]
\addplot[thick,red,domain=\pgfkeysvalueof{/pgfplots/xmin}:{\pgfkeysvalueof{/pgfplots/xmax}/1.3}] {x^2};
\draw [black, thick] (1,12.7) -- (2.5,12.7);
\draw [blue, thick] (0,\pgfkeysvalueof{/pgfplots/ymax}+0.3*\pgfkeysvalueof{/pgfplots/ymax}-0.3*\pgfkeysvalueof{/pgfplots/ymin}) -- (4,\pgfkeysvalueof{/pgfplots/ymax}+0.3*\pgfkeysvalueof{/pgfplots/ymax}-0.3*\pgfkeysvalueof{/pgfplots/ymin});
\end{axis}
\end{tikzpicture}
\end{document}
This is based on @koleygr answer. In this particular example ymin=1, ymax=10 and they are not set explicitly by user. Hence blue and black lines should have the same y-coordinate, but they are not. And how to simplify input by setting a new variable with all that staff \pgfkeysvalueof{/pgfplots/ymax}+0.3*\pgfkeysvalueof{/pgfplots/ymax}-0.3*\pgfkeysvalueof{/pgfplots/ymin}?
Ideally I woild like to place objects (lines, rectangles etc.) above the main graph (above y=10 in this particular example) and the distance these objects are shifted from ymax should depend on the size of the main graph, i.e. y-coordinate-of-objects = ymax + 0.3*(ymax - ymin).

rel axis cs. I mean, the y-coordinate in your last line there should be the same as that ofrel axis cs:0,1.3. – Torbjørn T. Sep 03 '17 at 06:57