Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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 nodes current axis.above origin, current axis.below origin, current axis.left of origin and current axis.right of origin.

\documentclass{standalone} 
\usepackage{pgfplots} 
\begin{document} 

\begin{tikzpicture} 
\begin{axis}[] 

\addplot[mark=none, domain=-2.5:2.5, thick, red] ({x},{x*x-0.5});% 

\draw (current axis.above origin) -- (current axis.below origin);
\draw (current axis.left of origin) -- (current axis.right of origin);

\end{axis} 
\end{tikzpicture} 
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.