I have two questions about the code below:

  1. How can I put the dashed lines in the right place (that is, from (0, 2) to (3, 2) to (3, 0))? At the moment they are in the wrong place.

  2. How can I move the x and y axis labels to be below and to the left of the axes respectively?


    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
    every axis y label/.style={at={(current axis.above origin)},anchor=north east}
    \begin{axis}[axis equal,
    x label style = {below=5mm},
                 axis lines=middle,
    \addplot[very thick, red!50, domain=0:360, samples=100, variable=\t] ({3+\n*cos(t)},{2+\n*sin(t)});
\coordinate (A) at (0,2);
\coordinate (B) at (3,2);
\coordinate (C) at (3,0);
    \draw[dashed] (A)--(B)--(C);

To 1.:
Here you placed the \coordinates outside the axis environment and thus you referred to the TikZ coordinate system instead of the axis one. But even if you would have placed them inside the axis environment this would have lead to the same result. Why and how this can be prevented/overcome is explained in the comments in the code.

To 2.:
Here you have placed the axis options in a "wrong" order. Your x label style attempt didn't work, because after that you have loaded the style axis lines=middle which itself has a x label style statement and thus "overrules" yours. Switching the order of the keys makes it work. But there is a better solution then yours which can also be found in the following code.

Besides that I did some other improvements to your code ...

% used PGFPlots v1.16
    % use this `compat` level or higher to make `axis cs:` the default
    % coordinate system for TikZ coordinates
        % (this has to be written near the beginning, thus other styles are
        % not overwritten again)
        axis lines=middle,
        axis equal,
%        % (this didn't work because it was overwritten by `axis lines`,
%        %  which originally was below this statement)
%        x label style={below=5mm},
        xlabel style={
            anchor=north east,
        ylabel style={
            anchor=north east,
        \addplot [
            very thick,
            % (by using smooth the default `samples=25` is perfectly fine)
        ] (

        % when `compat` level is 1.11 or higher, TikZ coordinates don't have
        % to be prepended by `axis cs:` (any more) because then this is the
        % default coordinate system
        \draw [dashed] (0,2) -| (3,0);
%        % ... thus, otherwise you have to write
%        \draw [dashed] (axis cs:0,2) -| (axis cs:3,0);

image showing the result of above code


A solution using pure TikZ, and the code seems to be much shorter:

\draw[-stealth] (0,-3)--(0,8) node[left] {$y$};
\draw[-stealth] (-3,0)--(8,0) node[below] {$x$};
\draw[dashed] (0,2) node[left] {2}--(3,2)--(3,0) node[below] {3};
\draw[red!50,very thick] plot[smooth,variable=\t,samples=100,domain=0:360] ({3+sqrt(13)*cos(\t)},{2+sqrt(13)*sin(\t)});

enter image description here

You can add option scale=... if you see the figure is too big (I think so).

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.