Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is it possible to add noise to the following function, which is piecewise constant?

Data:

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

Code:

\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}
share|improve this question
1  
A modification of the solutions to Adding vertical noise to a path should work here. –  Andrew Swann Dec 3 '12 at 13:36

1 Answer 1

You can add some noise to the values of a table by setting y expr=\thisrow{energy}+0.1*rnd instead of y=energy (for example).

\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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.