如何在图形周围添加空间 - pgfplots

如何在图形周围添加空间 - pgfplots

这是我的代码:

\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}

在输出中,两个轴都只从 -2 到 2。有没有办法让两个轴都从 -3 到 3?我无法在这里更改域,因为这是一个参数图。谢谢你的帮助。

答案1

有几种方法可以实现这一点。这里我展示了其中两种。请查看代码中的注释。

(此外,我还对您的一些代码进行了评论,以防您不知道这些内容。)

% 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}

该图显示了上述代码的结果

答案2

只需添加xminxmax

\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}

在此处输入图片描述

相关内容