I have macros that use anchor points in pgfplots to access certain coordinate. For instance, in a graph I can invoke a macro such as:
\newcommand*{\DoSomethingWithXAxis}{%
\draw [ultra thick, blue] (current axis.left of origin) -- (current axis.right of origin);
}
I would like to be able to reuse such macros in a basic tikzpicture
environment by manually defining the coordinates (current axis.left of origin)
and (current axis.right of origin)
. The problem stems from the fact that those are anchor points, so was wondering what is the simplest approach to set those.
Notes:
- I realize that
\DoSomethingWithXAxis
presented here is not very interesting and that there are easier ways to accomplish the same goal. But, this is just a MWE, with emphasis on theM
part of theMWE
.
The MWE below has \DoSomethingWithXAxis
commented out in the first tikzpicture
and yields the following. The desired result is for the tikzpicture
axis to also be in blue via \DoSomethingWithXAxis}
.
References:
Code:
\documentclass{article}
\usepackage{pgfplots}
\newcommand*{\DoSomethingWithXAxis}{%
\draw [ultra thick, blue] (current axis.left of origin) -- (current axis.right of origin);
}
%% Only specifying one side to ensure that this works with both
%% manually specified end point and an auto determined one.
\newcommand*{\XMax}{8}
\begin{document}
\begin{tikzpicture}
\draw [-latex] (1,0) -- (\XMax,0) node [above, pos=0.5] {tikzpicture};
%% Don't think these coordinates are being set correctly?
\coordinate (current axis.left of origin) at (1,0);
\coordinate (current axis.right of origin) at (\XMax,0);
%\DoSomethingWithXAxis;%%% <---- How do this ????
\end{tikzpicture}
\par\medskip
\begin{tikzpicture}
\begin{axis}[axis lines=middle, samples=50, xmax=\XMax]
\addplot [mark=none, red, thick] {x*x} node [pos=0.75, right] {pgfplots};
\DoSomethingWithXAxis;
\end{axis}
\end{tikzpicture}
\end{document}
left of origin
etc. are anchors of the shapepgfplots@low@level@shape
but to set them you need to be inside an axis because otherwise the macros that set them do not have all necessary information. Do you want to create another shape that allows you to set these anchors as you want, i.e. by hand?pgf
to create shapes. I want to be able to define the point that is meant by(current axis.right of origin)
outside of anaxis
environment. Desire is to not need two versions of each of those macros: one that works inside anaxis
environment and one that works in atikzpicture
(outside of anaxis
environment).