Smoothing your data

As an option to the plot command, gnuplot offers several smoothing functions. The name smooth is a bit misleading. Included in the options for the smooth plotstyle are several ways to process your data that would not most naturally be described as smoothing. We give examples of some of these in the following recipes. In the current recipe we show how to use the smoothing option that seems to be most immediately useful if you have some noisy data and want to draw a qualitatively smooth curve through it, to, as they say, guide the eye.

Getting ready

This recipe uses the datafile rs.dat; make sure that it is in your current directory. This file contains two columns that are the x and y coordinates of a simple sine wave of frequency and amplitude 1 to which normally distributed random data centered on 0 is added; that is, a sine curve plus the type of noise that might arise from actual measurements. In the following figure, we have a plot of the noisy sine wave, plotted with a thin line, overlaid with a thick curve showing the bezier smoothed approximation to the data, computed by gnuplot:

Getting ready

How to do it…

Use the following script to obtain the previous figure:

plot 'rs.dat' with lines lw 0.5 notitle, 
'' smooth bezier lw 4 title "Bezier Smoothed"

How it works…

The plot command is broken over two lines to make it easier to read; we've used one of gnuplot's special filenames, namely the empty string, which stands for the datafile previously read in, to avoid typing its name twice. The first part of the plot command is straightforward; we've asked for a thin line so that the smoothed overlay will be easier to see, and decided that we don't want a name for this curve to appear in the legend. The second part of the plot command contains the new feature smooth bezier; this tells gnuplot to compute a bezier curve to fit the data and plot that rather than the data itself. We see that the smoothed curve does a nice job of graphically summarizing the trend in the data, although it is a little bumpy. This is considered a simple smoothing option, and there are no adjustments for it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.5.57