我在 Tikz 中有下图(参见下面的 MWE)。我有一个直线方程。我通过绘制相同的方程但更改了 来生成误差line width
。但是,在图的 RHS 上,这以具有非垂直截止的误差线结束。如何纠正这个问题?
相关主题在这个帖子。但是,我还没有找到解决方法。有什么建议吗?
平均能量损失
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\definecolor{RoyalAzure}{rgb}{0.0, 0.22, 0.66}
\newcommand\randompath[2]{%
\pgfmathsetseed{#1}%
\addplot[#2,domain=0:1,samples=5,smooth] {0.02*(x+0.2)^(-0.4) -0.19 + (x+0.2)+rand*(x+0.32)*(1-(x+0.2))};%
}
\pgfplotsset{
/pgfplots/layers/mylayer/.define layer set=
{axis background,axis grid,main,axis ticks,axis lines,axis tick labels,axis descriptions,axis foreground}
{/pgfplots/layers/standard}}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{set layers=mylayer}%
\pgfplotsset{/dummy/workaround/.style={/pgfplots/axis on top}}
\begin{axis}[width=\columnwidth,
height=0.618\columnwidth,
axis x line=bottom,
axis y line=left,
axis line style={line width=1pt},
/dummy/workaround,
xlabel style = {font=\Large, xshift=31ex,yshift=2.5ex},
ylabel style = {font=\Large, rotate = -90, xshift=3.5ex, yshift=15.5ex},
xlabel={$\theta$},
ylabel={$\langle M\rangle$},
xmin=0,
xmax=1,
ymin=0,
ymax=1,
ticks=none,
]
\randompath{19.2}{RoyalAzure!10!white, line width=14pt} % ERROR FUNCTION
\randompath{19.2}{RoyalAzure, line width=1pt} % ACTUAL FUNCTION
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果我破坏了你的太多设置,我提前道歉。我在这里提出的建议是
declare function
通过和存储随机函数- 用来
fillbetween
遮蔽通过添加或减去某个常数而从原始函数中产生的两个函数之间的区域。
我为什么要弄乱你的设置?你设置图层的方式似乎与不一致fillbetween
。一旦我删除图层,其他东西就会变得疯狂,所以我就删除了这些东西。(抱歉!)
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\definecolor{RoyalAzure}{rgb}{0.0, 0.22, 0.66}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={% step 1 : define random function
myf(\x)=0.02*(\x+0.2)^(-0.4) -0.19 + (\x+0.2)+rand*(\x+0.32)*(1-(\x+0.2));}]
%\pgfplotsset{set layers=mylayer}%
\pgfplotsset{/dummy/workaround/.style={/pgfplots/axis on top}}
\begin{axis}[width=\columnwidth,
height=0.618\columnwidth,
axis x line=bottom,
axis y line=left,
axis line style={line width=1pt},
/dummy/workaround,
xlabel style = {font=\Large},
ylabel style = {font=\Large},
xlabel={$\theta$},
ylabel={$\langle M\rangle$},
xmin=0,
xmax=1,
ymin=-1,
ymax=2.5,
ticks=none,
]
\pgfmathsetseed{2}%
\addplot[domain=0:1,samples=5,smooth,opacity=0,name path=A] {myf(x)+0.15};
\pgfmathsetseed{2}%
\addplot[domain=0:1,samples=5,smooth,opacity=0,name path=B] {myf(x)-0.15};
\addplot[RoyalAzure!10!white] fill between [of=A and B];
\pgfmathsetseed{2}%
\addplot[domain=0:1,samples=5,smooth,RoyalAzure] {myf(x)};
\end{axis}
\end{tikzpicture}
\end{document}