6

I am trying to plot some experimental data. When I plot the data using tikzpicture/pgfplots, the data seems "noisy". It becomes less "noisy" when I use the keyword each nth point={n}, where I increased n to 1, 10, 50, 100 (see attached picture). However, when increasing n, I am essentially not being true to my recording. I was wondering if you could help me remove the "noise" that seems artificial while using my whole data set.

every n={1} every n is 1

every n={10} every n is 10

every n={50} every n is 50

every n={100} every n is 100

The code I use is as follows:

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usepgfplotslibrary{external}
\tikzsetexternalprefix{figurescache/}
\pgfplotsset{compat=newest}
\tikzset{external/system call={lualatex \tikzexternalcheckshellescape -shell-escape -synctex=1 -halt-on-error -jobname "\image" "\texsource"}}
\tikzexternalize[mode=list and make]
\begin{document}

\begin{tikzpicture}[scale=0.6]
\begin{axis}[hide x axis, ymax={90}, ymin={-90}, xmin={0}, xmax={400}]
\addplot[very thick, color=black, each nth point={1}]table[x=t,y=rec]  {./data/fig1data.dat};
\end{axis} 
\end{tikzpicture}
\end{document}

Edit: @Darthbith suggested I add the option /tikz/line join=bevel to my axis. It does a phenomenal job in removing the noise. There is a tiny bit of jaggedness when you zoom in to the plot, but it is already great. Here is the link to data I have used in the plots I have attached to this post.

  • 1
    Can you add to your axis options /tikz/line join=bevel? That should fix it. If it doesn't, please post some sample data that we can use – darthbith Dec 23 '15 at 1:34
  • @darthbith Wow! Thanks that fixed it! it is still a tiny bit noisy especially when I zoom; but that's probably because I am asking too much, but it is good. Thanks again! Are there any other options for the /tikz/line join=bevel I can try? Here is the link to the data: pastebinLink. I will add the link to my original post. – ZanCoul Dec 23 '15 at 1:54
  • 1
    You can find the documentation on page 167 of the PGF manual. miter is the default, and round is the other option. There's nothing you can do about the noise when you zoom, that's just noise in the data most likely. I'll post this as an answer when I get a chance. – darthbith Dec 23 '15 at 2:28
  • 1
    It looks better and is truer with the noise. That is data noise and it is best showing it -- it tells the reader about the extent of measurement noise versus underlying signal. – Aubrey Blumsohn Dec 23 '15 at 9:12
  • 2
    @AubreyBlumsohn: See the answer from darthbith below. The miter option actually exaggerates the noise. On the right side of darthbith's image, moving the bottom points closer together will cause the miter at the top to get taller. – James Dec 28 '15 at 20:21
8

You can add the option /tikz/line join=bevel to the axis options. This causes PGFPlots to draw the line segments between points with beveled edges instead of sharp (mitered) edges. The other options for line join are miter and round, which are shown below.

enter image description here

With a large number of data points spaced relatively close together in the x-axis and relatively large changes in the y-axis, the miter default option often produces the appearance of noise. Using bevel causes the drawing not to go much past where the point actually is. You can also look at the option /tikz/miter limit. Both of these options are described on page 167 of the PGF 3.0.1a manual.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
    hide x axis,
    ymax={90},
    ymin={-90},
    xmin={0},
    xmax={400},
    /tikz/line join=bevel,
]
\addplot[very thick, color=black] table[x=t, y=rec]  {texexchange_data.txt};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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