donkey
donkey

Reputation: 23

gnuplot smooth interpolation does not maintain data order

Here's my data:

data.txt (1st column is X; 2nd column is Y):
30 16
26 24
28 30
73 36

When I chart this in excel using "scatter with smooth lines", I get a picture like this:

desired chart from excel

However, I am unable to find an equivalent in gnuplot. Basically, when I do something like this:

plot 'data.txt' u 1:2 w p, 'data.txt' u 1:2 smooth csplines lw 2 notable

The data in the x-axis is first sorted before doing the smooth interpolation. This destroys the order of the data and results in a funky chart like this:

problem chart from gnuplot

I have tried every other smooth option, bezier is an improvement but does not connect 2 of my data point. Wondering if this is even possible to do in gnuplot. Thank you!

Upvotes: 2

Views: 224

Answers (1)

Matthew
Matthew

Reputation: 7590

This isn't really possible in gnuplot. The meaning of smooth lines in Excel and smooth in gnuplot are not really the same.

In Excel, it does mean to use smooth lines instead of straight lines.

In gnuplot it means to apply one of many possible transformations to the data. If you read the documentation on each one, you will see that almost all of them say that they first "make the data monotonic", which means that the data is first sorted. Notice as well, that most of them do not work with the original data, but some transformation of the data.

If it is a feature that you need, I see no obvious reason why it isn't something that could be added (a smoothlines plot style). The gnuplot page on sourceforge does allow users to submit feature requests. See the feature request page to do that.

Upvotes: 1

Related Questions