在下图中,洋红色曲线与青色曲线使用相同的函数绘制,但洋红色曲线以参数形式给出,与\addplot ({x},{f(x)});
和类似,因此采样方式显然不同。增加样本数量会有所帮助,但除非您添加大量样本并且编译时间会大大减慢,否则绘图看起来不正确。我如何告诉 pgfplots 针对参数形式进行适当采样?MWE 如下。解决方案\addplot gnuplot
是可以接受的,我也想不出。
\documentclass[margin=6]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode = log,
ymode = log,
axis lines = left,
ticks=none,
ylabel={$y_2$},
xlabel={$y_1$},
line width=2pt
]
\addplot [domain=1e-10:1e10,magenta] ({x},{1.0/(1.0+x)});
\addplot [domain=1e-10:1e10,cyan] {1.0/(1.0+x)};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以用samples at
它来实现这一点。
\documentclass[margin=6]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\newcounter{iloop}
\begin{document}
\begin{tikzpicture}
\setcounter{iloop}{-10}
\edef\mysamples{1e-10}
\loop
\edef\mysamples{\mysamples,1e\number\value{iloop}}%
\stepcounter{iloop}%
\ifnum\value{iloop}<11\repeat
\begin{axis}[
xmode = log,
ymode = log,
axis lines = left,
ticks=none,
ylabel={$y_2$},
xlabel={$y_1$},
line width=2pt
]
\addplot [magenta,samples at=\mysamples] ({x},{1.0/(1.0+x)});
\addplot [domain=1e-10:1e10,cyan] {1.0/(1.0+x)};
\end{axis}
\end{tikzpicture}
\end{document}
这是尝试将其塑造成一种风格。它似乎工作得很好,但努力似乎很高,也许一些fpu
专家可以把它简化成更短的东西。你只需要添加
log samples=between 1e-10 and 1e10 with next sample 3e-10
其中第一个值是第一个样本,第二个值是最后一个样本,第三个值是第二个样本。如果您想要不同的符号,请告诉我。
\documentclass[margin=6]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\makeatletter
\def\prepare@log@list#1#2#3{\pgfmathfloatparsenumber{#1}%
\pgfmathfloattomacro{\pgfmathresult}{\Fx}{\Mx}{\Ex}%
\pgfmathfloatparsenumber{#2}%
\pgfmathfloattomacro{\pgfmathresult}{\Fy}{\My}{\Ey}%
\pgfmathfloatparsenumber{#3}%
\pgfmathfloattomacro{\pgfmathresult}{\Fz}{\Mz}{\Ez}%
\pgfmathsetmacro{\xstart}{log10(\Mx)+\Ex}%
\pgfmathsetmacro{\xlast}{log10(\My)+\Ey}%
\pgfmathsetmacro{\xnext}{log10(\Mz)+\Ez}%
\foreach \XX [count=\YY] in {\xstart,\xnext,...,\xlast}%
{\pgfmathsetmacro{\myx}{\XX}%
\pgfmathtruncatemacro{\myy}{int(\XX)}%
\pgfmathsetmacro{\myz}{pow(10,\myx-int(\XX))}%
\ifnum\YY=1
\xdef\pgfutil@tempa{\myz e\myy}%
\else
\xdef\pgfutil@tempa{\pgfutil@tempa,\myz e\myy}%
\fi}}
\pgfplotsset{log samples/.style args={between #1 and #2 with next sample #3}{
/utils/exec=\prepare@log@list{#1}{#2}{#3},samples at=\pgfutil@tempa
}}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode = log,
ymode = log,
axis lines = left,
ticks=none,
ylabel={$y_2$},
xlabel={$y_1$},
line width=2pt
]
\addplot [magenta,log samples=between 1e-10 and 1e10 with next sample 3e-10] ({x},{1.0/(1.0+x)});
\addplot [domain=1e-10:1e10,cyan] {1.0/(1.0+x)};
\end{axis}
\end{tikzpicture}
\end{document}