我需要添加 trig format = rad 才能使绘图工作,但它会弄乱 y 轴。尝试在它前面添加一个 %,你就会明白我的意思。
这是我的 MWE:
\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
trig format = rad,
view={0}{90},
xmax=10, xmin=-10, ymax=10, ymin=-10,
zmin=-1, zmax=1,
zticklabels={\empty}]
\end{axis}
\end{tikzpicture}
\end{document}
这是非最小工作示例:
\documentclass[12pt]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=center,
trig format = rad,
view={0}{90},
domain=-10:10,
y domain=-10:10,
xmax=10, xmin=-10, ymax=10, ymin=-10,
zmin=-1, zmax=1,
samples=21,
zticklabels={\empty}
]
\addplot3 [gray, quiver={u={1},
v={cos(x)},
scale arrows=0.75, every arrow/.append style={-}}] (x,y,0);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
几乎最少的代码:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
axis lines=center,
legend pos=outer north east,
trig format = rad,
xlabel = $x$,
ylabel = $y$,
ymin=-1.5,
ymax=1.5
]
\addplot[magenta] [domain=-2*pi:2*pi, smooth, line width=3pt] { sin(x)};
\addlegendentry{\(y=\sin x\)}
\addplot[cyan] [domain=-2*pi:2*pi, smooth, line width=3pt] { cos(x)};
\addlegendentry{\(y=\cos x\)}
\end{axis}
\end{tikzpicture}
\end{document}
输出:
添加针对 OP 请求。
像这样:
新代码:
\documentclass[border=.5cm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
trig format = rad,
view={90}{90},
xmax=10, xmin=-10, ymax=5, ymin=-5,
zmin=-1, zmax=1,
zticklabels={\empty}
xlabel = $x$,
ylabel = $y$,
zlabel = $z$,
ymin=-1.5,
ymax=1.5
]
\addplot[magenta] [domain=-2*pi:2*pi, smooth, line width=3pt] { sin(x)};
\addlegendentry{\(y=\sin x\)}
\addplot[cyan] [domain=-2*pi:2*pi, smooth, line width=3pt] { cos(x)};
\addlegendentry{\(y=\cos x\)}
\end{axis}
\end{tikzpicture}
\end{document}