In the MWE example below I have the values specified twice, but would prefer not to have to do that. Furthermore, it is possible to allow PGFplots to automatically select these end points so I would have to iterate and modify the settings manually after seeing what PGFplots had selected. There must be some way to access these variables form within the axis
environment:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-1.5, xmax=1.5, ymin=-1, ymax=3]
\addplot[mark=none, domain=-2.5:2.5, thick, red] ({x},{x*x-0.5});%
% Would prefer to be able to specify something like this:
%\addplot [mark=none, blue, ultra thick] coordinates {(\xmin,\ymin) (\xmin,\ymax)};
% But until I can access those values, do it manually:
\addplot [mark=none, blue, ultra thick] coordinates {(-1.5,-1) (-1.5,3)};
\end{axis}
\end{tikzpicture}
\end{document}
In case there is an interest in why I want to do this: I am trying to automate labelling intersections with the lines x=0 and y=0 within PGFplots as discussed in How to specify a name path for the axis in PGFplots. However, there are issues with that approach. One solution (albeit it is a bit of a hack) is to draw the lines x=0, and y=0 with draw=none
option and then find the intersection with that. If I can access the min/max values of the x and y axis then I can label a phantom line and automate the location of the intersections via Intersections in PGFplots
Best Answer
You can access the values of
xmin
,xmax
, etc. through\pgfkeysvalueof{/pgfplots/xmin}
. This only works if they have been set explicitly in the axis options, though, so it is most likely not what you want. Instead, you should use the nodescurrent axis.above origin
,current axis.below origin
,current axis.left of origin
andcurrent axis.right of origin
.