如何用 tikz 在 pgfplots 圖上繪製一個半徑為 x 的簡單圓?

如何用 tikz 在 pgfplots 圖上繪製一個半徑為 x 的簡單圓?

我在使用 tikz 在圖表上繪製簡單的圓圈時遇到問題。當我嘗試文檔中的案例或不同問題的其他範例時,我得到一個對角線橢圓。這是我到目前為止所擁有的。

\documentclass[12pt]{extarticle}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}[scale=0.8]
  \begin{axis}[
    axis y line=center,
    axis x line=middle, 
    axis on top=false,
    xmin=-6.5, xmax=6.5,
    ymin=-6.5, ymax=6.5,
    grid, 
    xtick={-6,...,6},
    xticklabels={-6,...,6},
    ytick={-6,...,6},
    yticklabels={-6,...,6},
    ]
     
    \draw (0,0) circle [radius=3];
    
  \end{axis}
\end{tikzpicture}

\end{document}

當我像這樣使用半徑時,我最終得到一個對角線橢圓: 在此輸入影像描述

然後我嘗試使用橢圓格式,將其更改\draw (0,0) circle [radius=3];\draw (0,0) circle (45pt and 45pt);正如您從結果中看到的那樣, 在此輸入影像描述 我得到一個圓,但它似乎只在 x 軸上對齊,並且超出了 y 軸。該圖實際上不是正方形,還是圓形的格式造成了問題?

答案1

添加到我的代碼後似乎保持\draw (x,y) circle[radius=?]工作正常。axis equal image我的最終工作版本是:


\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}[scale=0.8]
  \begin{axis}[
    axis y line=center,
    axis x line=middle, 
    axis on top=false,
    axis equal image,
    xmin=-6.5, xmax=6.5,
    ymin=-6.5, ymax=6.5,
    grid, 
    xtick={-6,...,6},
    xticklabels={-6,...,6},
    ytick={-6,...,6},
    yticklabels={-6,...,6},
    ]   

    \draw (1,3) circle[radius=37pt];
  \end{axis}

\end{tikzpicture}

\end{document}

透過將繪圖保持在軸內,我在定位圓時沒有任何其他問題。

相關內容