我无法在 pgfplots 中绘制半圆

我无法在 pgfplots 中绘制半圆

我是 LaTEX 和 pgfplots 的新手,一直想画一个半圆,但总是画出奇怪的抛物线。我该如何解决这个问题?

\begin{tikzpicture}
\begin{axis}[
    axis lines = center,
    xlabel = \(x\),
    ylabel = {\(f(x)\)},
]
%Below the red parabola is defined
\addplot [
    domain=-10:10, 
    samples=100, 
    color=red,
]
{sqrt{9-x^2} };

\end{axis}
\end{tikzpicture}

答案1

像这样:

在此处输入图片描述

代码:

\documentclass[10pt,a4paper]{article}

\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[axis equal,
            axis lines = center,
            xlabel = \(x\),
            ylabel = {\(f(x)\)},
            xmin=-3.5,
            xmax=3.5,
            ]
            %Below the red semicircle is defined
            \addplot [line width=2pt,
            domain=-3:3, 
            samples=100, 
            color=red,
            ]
            {sqrt(9-x^2) };     
        \end{axis}
    \end{tikzpicture}
\end{document}

相关内容