How can I use math operators within PGFPlots coordinates?
When I write something like \draw (axis cs: 0,0) -- (axis cs: sqrt(3),1)
, I get the following error:
¡ Argument of \pgfplots@evalute@tikz@coord@system@interface@ has an extra }.
However, \draw (0,0) -> ({sqrt(3)},1)
works fine in Tikz, as long as sqrt(3)
is written inside of braces {}
.
If I add the braces to the PGFPlots code, I get the follwing error:
¡ Package PGF Math Error: Could not parse input '-{sqrt(3)}/2' as a floating po int number, sorry. The unreadable part was near 'sqrt(3)/2'..
MWE:
\documentclass{memoir}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.8,
standard/.style={
axis x line=center,
axis y line=center,
axis z line=center,
xlabel={$x$},
ylabel={$y$},
zlabel={$z$},
axis line style=help lines,
every axis/.append style={font=\tiny},
}
}
\begin{document}
{\centering
\begin{tikzpicture}[scale=1]
\begin{axis}[
standard,
hide z axis,
xmin=-1.25, xmax=1.25,
ymin=-1.25, ymax=1.25,
zmin=0, zmax=2.5,
xtick={-1,1},
xticklabels={$-2r$,$2r$},
ytick=\empty,
]
% Draw Circle
\draw[blue] (axis cs: 0,0,0)
ellipse [
x radius=1, y radius=1];
% Draw Square
\draw[green] (axis cs: -0.86602540378,0.5,0) --
(axis cs: -0.86602540378,-0.5,0) --
(axis cs: -0.86602540378,-0.5,1) --
(axis cs: -0.86602540378,0.5,1) --
(axis cs: -0.86602540378,0.5,0);
% I can't use math operators within PGFPlots apparently?
% \draw[green] (axis cs: -sqrt(3)/2,1/2,0) --
% (axis cs: -sqrt(3)/2,-1/2,0) --
% (axis cs: -sqrt(3)/2,-1/2,1) --
% (axis cs: -sqrt(3)/2,1/2,1) --
% (axis cs: -sqrt(3)/2,1/2,0);
\end{axis}
% However, I am able to do so in regular Tikz, as long as I put functions like sqrt() in braces...
\draw[green] (-{sqrt(3)/2},1/2,0) ->
(-{sqrt(3)/2},-1/2,0) ->
(-{sqrt(3)/2},-1/2,1) ->
(-{sqrt(3)/2},1/2,1) ->
(-{sqrt(3)/2},1/2,0);
\end{tikzpicture}
}
\end{document}