是否可以向以下分段常数函数中添加噪声?
数据:
time energy
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 1.8
12 1.8
13 1.8
14 1.8
15 1.8
16 0.8
17 0.8
18 0.8
19 0.8
20 0.8
21 0.8
22 0.8
23 0.8
24 0.8
25 0.3
26 0.3
27 0.3
28 0.3
29 0.3
30 0.3
31 0.3
32 0.3
33 0.3
34 0.3
36 0.3
37 0.3
38 0.3
39 0.3
40 0.3
41 0.3
42 0.3
43 0.3
44 0.3
45 0.3
46 0.3
代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=newest}
\begin{document}
\pgfplotstableread
{energy.dat}
{\table}
\begin{tikzpicture}
\begin{axis}[
ymin=0,
minor tick num=4,
enlarge x limits=false,
axis on top,
every axis plot post/.append style=
{mark=none},
const plot,
legend style={
area legend,
at={(0.5,-0.15)},
anchor=north,
legend columns=-1}]
\addplot[draw=blue,fill=blue!30!white]
table[x=time,y=energy] from \table
\closedcycle;
\legend{energy}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
y expr=\thisrow{energy}+0.1*rnd
您可以通过设置而不是y=energy
(例如)来向表的值添加一些噪音。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots, pgfplotstable}
\pgfplotsset{width=7cm,compat=newest}
\begin{document}
\pgfplotstableread
{
time energy
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
10 1.8
12 1.8
13 1.8
14 1.8
15 1.8
16 0.8
17 0.8
18 0.8
19 0.8
20 0.8
21 0.8
22 0.8
23 0.8
24 0.8
25 0.3
26 0.3
27 0.3
28 0.3
29 0.3
30 0.3
31 0.3
32 0.3
33 0.3
34 0.3
36 0.3
37 0.3
38 0.3
39 0.3
40 0.3
41 0.3
42 0.3
43 0.3
44 0.3
45 0.3
46 0.3
}
{\table}
\begin{tikzpicture}
\begin{axis}[
ymin=0,
minor tick num=4,
enlarge x limits=false,
axis on top,
every axis plot post/.append style=
{mark=none},
const plot,
legend style={
area legend,
at={(0.5,-0.15)},
anchor=north,
legend columns=-1}]
\addplot[draw=blue,fill=blue!30!white]
table[y expr=\thisrow{energy}+(rnd/10),x=time] \table
\closedcycle;
\legend{energy}
\end{axis}
\end{tikzpicture}
\end{document}