我(现在)有 $y = \sin^{2}(x) + \cos(x)$ 的图。我想绘制此函数在 $-2\pi$ 和 $2\pi$ 之间的临界数字处的点。我尝试使用命令
\draw [fill=blue] ({\pi/3},1.25) circle [radius=1.5pt];
例如。我收到一个错误。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=4in,axis on top,clip=false,
axis lines=middle,
xmin=-8.25,xmax=8.25,
ymin=-1.5,ymax=1.5,
restrict y to domain=-1.5:1.5,
ticklabel style={font=\tiny},
xtick={-7.33038, -3.14159, -1.0472, 1.0472, 3.14159, 7.33038},
xticklabels={\makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{7\pi}{3}$, \makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\pi$, \makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\pi$, $\scriptstyle\dfrac{7\pi}{3}$},
xlabel=$x$,ylabel=$y$,
ytick={-1, 1.25},
yticklabels={$\scriptstyle-1$, $\scriptstyle\dfrac{5}{4}$},
axis line style={latex-latex},
enlargelimits={abs=0.25cm},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=201,domain=-8:-6.283185, dashed] {(sin(deg(x)))^2 + cos(deg(x))} ;
\addplot[samples=201,domain=-6.283185:6.283185] {(sin(deg(x)))^2 + cos(deg(x))}
\addplot[samples=201,domain=6.283185:8, dashed] {(sin(deg(x)))^2 + cos(deg(x))}
\draw [fill=blue] ({-\pi/3},1.25) circle [radius=1.5pt];
\draw [fill=blue] ({\pi/3},1.25) circle [radius=1.5pt];
\draw [fill=blue] ({-pi},-1) circle [radius=1.5pt];
\draw [fill=blue] (\pi,-1) circle [radius=1.5pt];
\draw [fill] ({-2*\pi},1) circle [radius=1.5pt];
\draw [fill] ({2*\pi},1) circle [radius=1.5pt];
\end{document}
答案1
\pi
是用于排版希腊字符的宏,它不是pgfmath
对应于接近 3.14 的数字的变量。您需要pi
,不带反斜杠。
您还需要确保在每个后面添加一个分号\addplot
,并且您遗漏了\end{axis}\end{tikzpicture}
。
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=4in,axis on top,clip=false,
axis lines=middle,
xmin=-8.25,xmax=8.25,
ymin=-1.5,ymax=1.5,
restrict y to domain=-1.5:1.5,
ticklabel style={font=\tiny},
xtick={-7.33038, -3.14159, -1.0472, 1.0472, 3.14159, 7.33038},
xticklabels={\makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{7\pi}{3}$, \makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\pi$, \makebox[0pt][r]{$\scriptstyle-$}$\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\dfrac{\pi}{3}$, $\scriptstyle\pi$, $\scriptstyle\dfrac{7\pi}{3}$},
xlabel=$x$,ylabel=$y$,
ytick={-1, 1.25},
yticklabels={$\scriptstyle-1$, $\scriptstyle\dfrac{5}{4}$},
axis line style={latex-latex},
enlargelimits={abs=0.25cm},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=201,domain=-8:-6.283185, dashed] {(sin(deg(x)))^2 + cos(deg(x))} ;
\addplot[samples=201,domain=-6.283185:6.283185] {(sin(deg(x)))^2 + cos(deg(x))};
\addplot[samples=201,domain=6.283185:8, dashed] {(sin(deg(x)))^2 + cos(deg(x))};
\draw [fill=blue] ({-pi/3},1.25) circle [radius=1.5pt];
\draw [fill=blue] ({pi/3},1.25) circle [radius=1.5pt];
\draw [fill=blue] ({-pi},-1) circle [radius=1.5pt];
\draw [fill=blue] (pi,-1) circle [radius=1.5pt];
\draw [fill] ({-2*pi},1) circle [radius=1.5pt];
\draw [fill] ({2*pi},1) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\end{document}
声明一个函数,删除\scriptstyle
没有多大作用的(您还有\tiny
),使用图来添加圆圈。
\documentclass[10pt]{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
declare function={f(\x)=(sin(deg(\x)))^2 + cos(deg(\x));},
width=4in,axis on top,clip=false,
axis lines=middle,
xmin=-8.25,xmax=8.25,
ymin=-1.5,ymax=1.5,
ticklabel style={font=\tiny},
xtick={-7.33038, -3.14159, -1.0472, 1.0472, 3.14159, 7.33038},
xticklabels={\makebox[0pt][r]{$-$}$\dfrac{7\pi}{3}$, \makebox[0pt][r]{$-$}$\pi$, \makebox[0pt][r]{$-$}$\dfrac{\pi}{3}$, $\dfrac{\pi}{3}$, $\pi$, $\dfrac{7\pi}{3}$},
xlabel=$x$,ylabel=$y$,
ytick={-1, 1.25},
yticklabels={$-1$, $\dfrac{5}{4}$},
axis line style={latex-latex},
enlargelimits={abs=0.25cm},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=21,domain=-8:-6.283185, dashed] {f(x)} ;
\addplot[samples=201,domain=-6.283185:6.283185] {f(x)};
\addplot[samples=21,domain=6.283185:8, dashed] {f(x)};
\addplot [blue,draw=none,mark=*] coordinates {
(-2*pi,{f(-2*pi)})
(-pi,{f(-pi)})
(-pi/3,{f(-pi/3)})
(pi/3,{f(pi/3)})
(pi,{f(pi)})
(2*pi,{f(2*pi)})
};
\end{axis}
\end{tikzpicture}
\end{document}