考虑下面的例子,它运行良好,但我们不太明白为什么。
如果我们改用,domain=-1:1
则会得到差距:
而domain=-2:2
给我们
正如我们所希望的。
同时如果我们在这种domain=-2:2
情况下改用samples=1000
我们得到
与第一幅图像相比,其间隙不同。
那里到底发生了什么,为什么在这种情况下domain=-2:2
+会起作用?samples=1001
如果相关,则使用 TL17 冻结进行编译。
梅威瑟:
\documentclass[10pt]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows.meta}
\tikzset{
>={Latex[round]},
declare function={
f(\x,\k)=(1-abs(\x)^(\k))^(1/\k);
},
}
\pgfplotsset{
setup/.style={
very thick,
width=5cm,
domain=-2:2,
samples=1001,
-,
unbounded coords=jump,
no marks,
unit vector ratio*=1 1 1,
% ticks=none,
axis lines = middle,
xmin = -1.2,
xmax=1.4,
ymin=-1.2,
ymax=1.4,
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,
},
},
every non boxed x axis/.append style={
axis line style=->
},
every non boxed y axis/.append style={
axis line style=->
},
}
\begin{document}
% q=2
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=2$},
]
\addplot[blue] {f(x,2)};
\addplot[blue] {-f(x,2)};
\end{axis}
\end{tikzpicture}
\qquad
%q=3
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=3$},
]
\addplot[red] {f(x,3)};
\addplot[red] {-f(x,3)};
\end{axis}
\end{tikzpicture}
\qquad
%q=4
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=4$},
]
\addplot[red] {f(x,4)};
\addplot[red] {-f(x,4)};
\end{axis}
\end{tikzpicture}
\qquad
% %q=6
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=6$},
]
\addplot[red] {f(x,6)};
\addplot[red] {-f(x,6)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
|x|>1
我认为问题在于,如果和,函数不再是实数k>1
。如果过滤掉有问题的值,就不会出现问题。
\documentclass[10pt]{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{arrows.meta}
\tikzset{
>={Latex[round]},
declare function={
f(\x,\k)=ifthenelse((1-abs(\x)^(\k))<0,0,(1-abs(\x)^(\k))^(1/\k));
},
}
\pgfplotsset{
setup/.style={
very thick,
width=5cm,
domain=-2:2,
samples=1000,
-,
unbounded coords=jump,
no marks,
unit vector ratio*=1 1 1,
% ticks=none,
axis lines = middle,
xmin = -1.2,
xmax=1.4,
ymin=-1.2,
ymax=1.4,
every axis y label/.style={
at={(ticklabel* cs:1)},
anchor=south,
},
},
every non boxed x axis/.append style={
axis line style=->
},
every non boxed y axis/.append style={
axis line style=->
},
}
\begin{document}
% q=2
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=2$},
]
\addplot[blue] ({ifthenelse(abs(x)>1,sign(x),x)},{f(x,2)});
\addplot[blue] ({ifthenelse(abs(x)>1,sign(x),x)},{-f(x,2)});
\end{axis}
\end{tikzpicture}
\qquad
%q=3
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=3$},
]
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{f(x,3)});
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{-f(x,3)});
\end{axis}
\end{tikzpicture}
\qquad
%q=4
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=4$},
]
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{f(x,4)});
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{-f(x,4)});
\end{axis}
\end{tikzpicture}
\qquad
% %q=6
\begin{tikzpicture}
\begin{axis}[
setup,
ylabel={$q=6$},
]
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{f(x,6)});
\addplot[red] ({ifthenelse(abs(x)>1,sign(x),x)},{-f(x,6)});
\end{axis}
\end{tikzpicture}
\end{document}