I'm trying to come up with a solution to the question How to maintain consistency with TikZ and Pgfplots?. Essentially, what is needed is a way to save a coordinate as a macro (or a global key, maybe?) that can then be used instead of the usual <x>,<y>
pair, both in normal nodes/paths and in pgfplots plots.
For clarification: I would like to be able to define a macro \PointA
that I can call whenever the syntax (<x>,<y>)
is expected. This might be in the definition of a node using \node at (<x>,<y>) {};
, or in a pgfplots plot using \addplot coordinates { (0,0) (<x>,<y>) (1,1) };
Just using \def\<name>{<x>,<y>}
works fine for normal nodes and paths, but when I try to use it as a coordinate in a pgfplots plot, it fails with the error message:
File ended while scanning use of \pgfplots@foreach@plot@coord@NEXT.
An expansion issue, yet again? Or should I use a totally different approach?
\documentclass{article}
\usepackage{pgfplots}
\def\PointA{1,2}
\begin{document}
\begin{tikzpicture}
\draw [gray] (0,0) grid (3,3);
\fill (\PointA) circle (2pt); % Works
\begin{axis}[xshift=3.5cm,width=6cm,xmin=0,xmax=3,ymin=0,ymax=3,grid=both]
\fill [orange] (axis cs:\PointA) circle (4pt); % Works
\addplot coordinates { (0,0) (1,2) (2,2) }; % Works
% \addplot coordinates { (0,0) (\PointA) (2,2) }; % Fails
\end{axis}
\end{tikzpicture}
\end{document}