我需要绘制函数y = -x cot (x)
,并且我制作了此图,但它报告错误“!尺寸太大”
我创建了这个图表这里
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis lines=middle,
axis on top,
xlabel=$x$,
ylabel=$y$,
domain=-2*pi:2*pi,
xmin=-7,
xmax=7,
ymin=-5,
ymax=5,
trig format plots=rad, %<-
xtick={-2*pi,-3*pi/2, -pi, -pi/2,pi/2,pi,3*pi/2,2*pi},
xticklabels={$-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
every axis y label/.style={rotate=0, black, at={(0.5,1.05)},},
every axis x label/.style={rotate=0, black, at={(1.05,0.5)},},,
font=\footnotesize,
]
\pgfplotsinvokeforeach{-5,-3,...,3}{
\pgfmathsetmacro{\xmin}{ifthenelse(#1==-5,-2*pi,#1*pi/2+0.01)}
\pgfmathsetmacro{\xmax}{ifthenelse(#1==3,2*pi,#1*pi/2+pi-0.01)}
\addplot[blue,samples=51,smooth,domain=\xmin:\xmax]{-x*cot(x)};
\draw[densely dotted] (#1*pi/2,\pgfkeysvalueof{/pgfplots/ymin})
-- (#1*pi/2,\pgfkeysvalueof{/pgfplots/ymax});
}
\end{axis}
\end{tikzpicture}
\end{document}
你能帮助我吗?
答案1
我不知道你为什么认为你可以用棕褐色的杆子做婴儿床。如果你选择合适的杆子,你就会得到
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis lines=middle,
axis on top,
xlabel=$x$,
ylabel=$y$,
domain=-2*pi:2*pi,
xmin=-7,
xmax=7,
ymin=-5,
ymax=5,
trig format plots=rad, %<-
xtick={-2*pi,-3*pi/2, -pi, -pi/2,pi/2,pi,3*pi/2,2*pi},
xticklabels={$-2\pi$, $-\frac{3\pi}{2}$, $-\pi$, $-\frac{\pi}{2}$, $\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$},
every axis y label/.style={rotate=0, black, at={(0.5,1.05)},},
every axis x label/.style={rotate=0, black, at={(1.05,0.5)},},,
font=\footnotesize,
]
\pgfplotsinvokeforeach{-4,-2,2}{%
\pgfmathsetmacro{\xmin}{ifthenelse(#1==-2,-pi+0.1,#1*pi/2+0.01)}
\pgfmathsetmacro{\xmax}{ifthenelse(#1==-2,pi-0.1,#1*pi/2+pi-0.01)}
\addplot[blue,samples=51,smooth,domain=\xmin:\xmax]{-x*cot(x)};
\addplot[densely dotted] coordinates {(#1*pi/2,\pgfkeysvalueof{/pgfplots/ymin})
(#1*pi/2,\pgfkeysvalueof{/pgfplots/ymax})};
}
\addplot[densely dotted] coordinates {(2*pi,\pgfkeysvalueof{/pgfplots/ymin})
(2*pi,\pgfkeysvalueof{/pgfplots/ymax})};
\end{axis}
\end{tikzpicture}
\end{document}