在 Geogebra 上生成 Tikz 代码时出现问题:半圆发生位移

在 Geogebra 上生成 Tikz 代码时出现问题:半圆发生位移

这是我在 Geogebra 中绘制的:

在此处输入图片描述

这是我从 Geogebra 导出 Tikz 文件时获得的代码:

\definecolor{ududff}{rgb}{0.30196078431372547,0.30196078431372547,1}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-4.370038701302235,
xmax=4.373881990999934,
ymin=-0.5693858009107018,
ymax=5.2038438869554735,
xtick={-4,-3,...,4},
ytick={0,1,...,5},]
\clip(-4.370038701302235,-0.5693858009107018) rectangle (4.373881990999934,5.2038438869554735);
\draw [line width=2pt] (-3,1)-- (3,1);
\draw [shift={(0,1)},line width=2pt]  plot[domain=0:3.141592653589793,variable=\t]({1*3*cos(\t r)+0*3*sin(\t r)},{0*3*cos(\t r)+1*3*sin(\t r)});
\begin{scriptsize}
\draw [fill=ududff] (-3,1) circle (0.5pt);
\draw [fill=ududff] (3,1) circle (0.5pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}

这就是我将其粘贴到我的 Latex 文档中得到的结果:

为什么我会得到这个?如何解决?我试过几次...

答案1

唯一的问题是 shift 命令没有声明 unit cm,(例如shift={(0cm,1cm)})。以下代码应该可以工作:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{xcolor}
\definecolor{ududff}{rgb}{0.30196078431372547,0.30196078431372547,1}

\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\begin{axis}[
x=1cm,y=1cm,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-4.370038701302235,
xmax=4.373881990999934,
ymin=-0.5693858009107018,
ymax=5.2038438869554735,
xtick={-4,-3,...,4},
ytick={0,1,...,5},]
\clip(-4.370038701302235,-0.5693858009107018) rectangle (4.373881990999934,5.2038438869554735);
\draw [line width=2pt] (-3,1)-- (3,1);
% The shift command has changed
\draw [shift={(0cm,1cm)},line width=2pt]  plot[domain=0:3.141592653589793,variable=\t]({1*3*cos(\t r)+0*3*sin(\t r)},{0*3*cos(\t r)+1*3*sin(\t r)});
\begin{scriptsize}
\draw [fill=ududff] (-3,1) circle (0.5pt);
\draw [fill=ududff] (3,1) circle (0.5pt);
\end{scriptsize}
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容