0

The following is what I have currently.

\newcommand\medlsquare[4]
{    
    \addplot[thick] coordinates { (#1, #2) (#1+#3, #2) (#1+#3, #2+#3) (#1, #2+#3) (#1, #2)
};

I want to reuse the co-ordinates like below

\newcommand\medlsquare[4]
{
\coordinate (#4A) at (#1, #2);
\coordinate (#4B) at (#1++3, #2);
\coordinate (#4C) at (#1+#3, #2+#3);
\coordinate (#4D) at (#1, #2+#3);

// what is the option do do something like below?
 \addplot[thick] coordinates {/#4A, /#4B, /#4C, /#4D};

};

1 Answers1

2

Instead of \addplot you can use \draw plot:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\newcommand{\medlsquare}[4]{%
\coordinate (#4A) at (#1, #2); \coordinate (#4B) at (#1+#3, #2); \coordinate (#4C) at (#1+#3, #2+#3); \coordinate (#4D) at (#1, #2+#3); \draw plot[thick] coordinates {(#4A) (#4B) (#4C) (#4D) (#4A)}; }

\begin{document} \begin{tikzpicture} \begin{axis}[xmin=0,xmax=3,ymin=0,ymax=3] \medlsquare{1}{1}{1}{square} \end{axis}

\draw[red] (squareA) -- (squareC); % created coordinates are still accessible

\end{tikzpicture} \end{document}

enter image description here