3

I am curious about the misinterpretation of TikZ commands to draw and label an angle in an axis environment. If, in the following code, I have $\theta$ drawn using the commands,

\draw[draw=blue] (A) ++(120:4mm) arc (120:0:4mm);
\coordinate (label_for_theta) at (60:5.5mm);
\node[font=\footnotesize] at (label_for_theta){$\theta$};

the angle and label are displayed as expected. I have, though,

\draw[draw=blue] (A) ++(120:0.4) arc (120:0:0.4);
\coordinate (label_for_theta) at (60:0.55);
\node[font=\footnotesize] at (label_for_theta){$\theta$};

and a mess is displayed. I understand that using the axis environment is superfluous - I am using it just to draw the axes. As I said, I am curious. (I know that I could use tkz-euclice. I am using this as an opportunity to get familiar with TikZ. I would prefer to avoid using this package, anyway.)

By the way, I typeset the vertex A properly with \node at (0.25,-0.25){$A$};, without units, and I typeset the vertex B properly with \node at (3.5,-2.5mm){$B$};, with units. I was told that specifying coordinates with dimensions within an axis environment would be misinterpreted.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}


\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=5,
    ymin=-1.5,ymax=5,
    restrict y to domain=-1.5:5,
    xtick={\empty},ytick={\empty},
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

%A triangle is drawn on the Cartesian plane. One side of the triangle is along
%the positive x-axis, and another side of the triangle is drawn in Quadrant II.
\coordinate (A) at (0,0);
\coordinate (B) at (3.5,0);
\coordinate (C) at ({5*cos(120)},{5*sin(120)});
\draw (A) -- (B) -- (C) -- cycle;

%The labels for A and B are typeset.
\node at (0.25,-0.25){$A$};
\node at (3.5,-2.5mm){$B$};
%The label for C is typeset.
\coordinate (label_C_left) at ($(C)!-4mm!(B)$);
\coordinate (label_C_right) at ($(C)!-4mm!(A)$);
\coordinate (label_C) at ($(label_C_left)!0.5!(label_C_right)$);
\node[blue] at ($(C)!2.5mm!(label_C)$){$C$};


%Angles are drawn for $\theta$ and its supplement.
\draw[draw=blue] (A) ++(120:0.4) arc (120:0:0.4);
\coordinate (label_for_theta) at (60:0.55);
\node[font=\footnotesize] at (label_for_theta){$\theta$};
\draw[draw=blue,dash dot] (A) ++(180:0.6) arc (180:120:0.6);
\coordinate (label_for_supplement_to_theta) at (150:0.75);
\node[font=\footnotesize] at (label_for_supplement_to_theta){$\pi - \theta$};


%A right-angle mark is drawn.
\coordinate (U) at ($(-2.5,0)!3mm!45:(A)$);
\draw[dash dot] (U) -- ($(-2.5,0)!(U)!(A)$);
\draw[dash dot] (U) -- ($(-2.5,0)!(U)!(C)$);


\draw[dashed] (C) -- (-2.5,0);

%Braces indicating the distances that C is from the axes are typeset. To give
%them the appearance of being typeset over the axes, they are first typeset
%in white with a line width of 2pt, which is 10 times the thickness of the
%brace that is actually typeset.
\draw[draw=white,line width=4pt,decorate,decoration={brace,raise=5pt,amplitude=5pt}] (-2.5,0) -- (C);
\draw[decorate,decoration={brace,raise=5pt,amplitude=5pt}] (-2.5,0) -- (C);
\draw[draw=white,line width=4pt,decorate,decoration={brace,raise=5pt,amplitude=5pt,mirror}] (-2.5,0) -- (A);
\draw[decorate,decoration={brace,raise=5pt,amplitude=5pt,mirror}] (-2.5,0) -- (A);


\coordinate (label_for_5_sin_theta) at ($({5*cos(120)},{2.5*sin(120)}) + (-2.5mm-10pt,0pt)$);
\node[anchor=east] at (label_for_5_sin_theta){$r\sin\theta$};
\coordinate (label_for_5_cos_theta) at (-1.25,-2.5mm-10pt);
\node at (label_for_5_cos_theta){$r\cos\theta$};

\end{axis}
\end{tikzpicture}
\end{document}
  • Did you read page 350 of the pgfplots manual? The fact that you are using width=5in, for example, is certainly going to alter the units. But, also, as Aleanno pointed out, it is a matter of the origin's location, too. – cfr Jul 24 '15 at 15:31
  • @cfr I will look now. (I have been editing another post.) Is this the web site? http://ctan.mirrorcatalogs.com/graphics/pgf/base/doc/pgfmanual.pdf Where did Aleanno leave a comment? – user74973 Jul 24 '15 at 15:37
  • I meant the answer to your other question. Best is texdoc pgfplots. What you are seeing is a result of pgfplots - not TikZ itself. As I said before, the axis environment is specialised and the coordinate systems used there do not map one-one onto TikZ coordinate systems unless set up specifically to do so. That is, unless you follow the restrictions explained on page 350. – cfr Jul 24 '15 at 16:30
  • @cfr Please give me the web site to the manual to which you are referring. I will have a similar post in about 15 minutes. I will send you a ping. (I see that you deleted most of our conversation. That is fine. I made many edits to my original post during our discussion. Again, thanks for your patience. I will delete this comment, too.) – user74973 Jul 24 '15 at 18:26
  • It is not deleted. It just moved to chat. – cfr Jul 24 '15 at 18:41
3

If you only want to use the axis environment to draw the axis, then don't try to do anything else with it. Note: the scope is used to shift the origin.

I also simplified your angle labels. Later I came back and simplified all of the labels.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds,patterns}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}


\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=5,
    ymin=-1.5,ymax=5,
    restrict y to domain=-1.5:5,
    xtick={\empty},ytick={\empty},
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\coordinate (origin) at (0,0);
\end{axis}
\begin{scope}[shift={(origin)}]
%A triangle is drawn on the Cartesian plane. One side of the triangle is along
%the positive x-axis, and another side of the triangle is drawn in Quadrant II.
\coordinate (A) at (0,0);
\coordinate (B) at (3.5,0);
\coordinate (C) at ({5*cos(120)},{5*sin(120)});
\draw (A) -- (B) -- (C) -- cycle;

\coordinate (D) at (A-|C);% horizontal to (A), vertical to (C)

%The labels for A and B are typeset.
\node[below right] at (A){$A$};
\node[below] at (B){$B$};
%The label for C is typeset.
\node[blue,above left] at (C) {$C$};


%Angles are drawn for $\theta$ and its supplement.
\draw[draw=blue] (A) ++(120:0.4) arc (120:0:0.4)
  node[midway,above right,inner sep=2pt,font={\footnotesize}]{$\theta$};
\draw[draw=blue,dash dot] (A) ++(180:0.6) arc (180:120:0.6)
  node[midway,left,inner sep=2pt,font={\footnotesize}]{$\pi - \theta$};

%A right-angle mark is drawn.
\draw[dash dot] (D) +(0,3mm) -- +(3mm,3mm) -- +(3mm,0);

\draw[dashed] (C) -- (D);

%Braces indicating the distances that C is from the axes are typeset. To give
%them the appearance of being typeset over the axes, they are first typeset
%in white with a line width of 2pt, which is 10 times the thickness of the
%brace that is actually typeset.
\draw[draw=white,line width=4pt,decorate,decoration={brace,raise=.5em,amplitude=.5em}] (D) -- (C);
\draw[decorate,decoration={brace,raise=.5em,amplitude=.5em}] (D) -- (C)
  node[midway,left=1em] {$r\sin\theta$};;
\draw[draw=white,line width=4pt,decorate,decoration={brace,raise=1ex,amplitude=1ex,mirror}] (D) -- (A);
\draw[decorate,decoration={brace,raise=1ex,amplitude=1ex,mirror}] (D) -- (A)
  node[midway,below=2ex] {$r\cos\theta$};
\end{scope}
\end{tikzpicture}
\end{document}

axis and scope

  • This is an efficient modification to my code. The display is exactly what I want. Thanks. I see that you added \coordinate (origin) at (0,0); and a scope environment with the option shift={(origin)}. What does adding the \coordinate command within the axis environment do? I guess the option to the scope environment aligns the origin of the axis environment with the origin of the scope environment. – user74973 Jul 24 '15 at 18:16
  • 2
    The axis environment uses its own coordinate system. \coordinate records (0,0) in the axis environment in terms of screen coordinates, and more importantly as a global value. Without the \begin{scope}[shift={(origin)}] the rest of the plot would be centered about the lower left hand corner of the axis. – John Kormylo Jul 24 '15 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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