0

This is my code:

\documentclass{article}
\usepackage{tikz, pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
    axis x line=middle,
        axis y line=middle,
        xtick={-3,-2,...,3},
        ytick={-3,-2,...,3}, 
        ylabel=$y$, 
        xlabel=$x$,
         xlabel style={below right},
  ylabel style={above left},
  samples=200,
  axis equal image
]
  \addplot [domain=-180:180, samples=100, color=red] ({2*cos(x)},{2*sin(x)});
\end{axis}
\end{tikzpicture}
\end{document}

In the output, both axes only go from -2 to 2. Is there a way to make both axes go from -3 to 3? I can't alter the domain here, since it's a parametric plot. Thanks for your help.

2

There are several ways to achieve this. Here I show two of them. Please have a look at the comments in the code.

(In addition I commented some of your code, just in case you are not aware of that stuff.)

% used PGFPlots v1.15
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis x line=middle,
        axis y line=middle,
        %--------------------
        % (this can be achieved in a simpler way)
%        xtick={-3,-2,...,3},
%        ytick={-3,-2,...,3},
        xtick distance=1,
        ytick distance=1,
        %--------------------
        ylabel=$y$,
        xlabel=$x$,
        xlabel style={below right},
        ylabel style={above left},
        % (this doesn't do anything, because you have added `samples' to the
        %  `\addplot' command as well)
%        samples=200,
        axis equal image,
        % ---------------------------------------------------------------------
        % either set the axis limits explicitly ...
%        xmin=-3,
%        xmax=3,
%        ymin=-3,
%        ymax=3,
        % ... or enlarge the limits relatively or like here absolutely
        enlargelimits={abs=1},
        % ---------------------------------------------------------------------
    ]
        \addplot [domain=-180:180, samples=100, color=red] ({2*cos(x)},{2*sin(x)});
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

1

Just add xmin and xmax etc.

\documentclass{article}
\usepackage{tikz, pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ 
    axis x line=middle,
        axis y line=middle,
        xtick={-3,-2,...,3},
        ytick={-3,-2,...,3}, 
        ylabel=$y$, 
        xlabel=$x$,
        xmin=-3,xmax=3, %<-added
        ymin=-3,ymax=3, %<-added
         xlabel style={below right},
  ylabel style={above left},
  samples=200,
  axis equal image
]
  \addplot [domain=-180:180, samples=100, color=red] ({2*cos(x)},{2*sin(x)});
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.