1

I would like to plot a csv file with gnuplot. Instead of a line, I want to use points that are evenly distributed along the path of the curve. However, the data in the csv file is not evenly distributed, e.g. like this

x,p
0,2
1,4
1.1,4.2
1.2,4.4
2.8,7.6
2.85,7.7
4,10

It should be possible to achieve this, but how?

Here is an example graph where I plot every nth point. Because my numerical solution is so good :-) you only see one line, so I would like to have markers on the one curve. But the points should be distributed equidistantly (the current distribution is only due to the nature of the analytical solution).

enter image description here

Ethan
  • 13,715
  • 2
  • 12
  • 21
scinopode
  • 15
  • 3
  • 1
    Welcome to StackOverflow! What have you tried so far? Do you have some code or some graph? So, you are asking about interpolation of values with equidistant sampling? – theozh Feb 04 '22 at 13:17
  • Yes, exactly that. I think this is done internally anyway (that's why you see dashed lineplots, unlike Excel where you don't see dashed lines if the data is too close together). I have edited my question and attached an example graph. – scinopode Feb 04 '22 at 13:47
  • Do you mean interpolation along the *path* or along the *x-axis*? – theozh Feb 04 '22 at 14:12
  • Path I had in mind – scinopode Feb 04 '22 at 14:17
  • A few years ago, I asked here about resampling (along x-axis) with gnuplot (https://stackoverflow.com/q/54362441/7295599).... still no good answer. gnuplot wants to be a plotting tool and therefore has rather limited data preparation features. I am confident that there will be some way with gnuplot, but most likely it will be a cumbersome workaround. Furthermore, if you want "along the path", you need to take the different x- and y-scales into account if you want to have "visually" equidistant points. – theozh Feb 04 '22 at 14:42
  • Some time ago, there was a question about hatched lines. For this, I used resampling along a path. Have a look at it how complicated it might get... https://stackoverflow.com/a/57685754/7295599 ...good luck! ;-) If you find a simpler gnuplot solution please let me know. – theozh Feb 04 '22 at 14:50
  • Ok, thanks @theozh, I will study your suggestions. – scinopode Feb 04 '22 at 15:00
  • Your question title is too general and doesn't reflect your request at all. I would suggest something more specific like "How to interpolate along a path with gnuplot?" What exactly is the reason that you want to have equidistant points along the path? Just to "look nicer"? Your points are measured or simulated data, well, that's how they are distributed. Actually, is the question about *interpolation* of new points or *skipping* existing points so that you get a more evenly distributed visual impression? – theozh Feb 04 '22 at 15:45
  • I just want to show a curve. This should stand out from another curve. If the curves were not on top of each other, I would simply show one solid and the other dashed. But they lie exactly on top of each other. I can choose different colours, then both curves are distinguishable. However, the graph should also be evaluable if it is printed out in black and white, for example. I only want to use the markers to distinguish the lines. After all, with a dashed line you wouldn't claim that the gaps between the dashes do not contain any data, would you?. – scinopode Feb 04 '22 at 21:47

1 Answers1

0

In the development version of gnuplot (5.5) this can be done exactly as asked. smooth path does what you would expect, and pn 7 tells it to place exactly 7 evenly spaced points.

$DATA << EOD
0,2
1,4
1.1,4.2
1.2,4.4
2.8,7.6
2.85,7.7
4,10
EOD

set log y
set key top left
set datafile separator comma

plot $DATA smooth path with lp pn 7 title "smooth path pn 7", \
     $DATA with points pt 6 ps 2 title "original points" 

enter image description here

The current version 5.4 does not offer smooth path, but if your data points are sufficiently close to lying on a smooth curve one of the other smoothing options, e.g. smooth mcs, may be acceptable.

For the record, I think this is not a good thing to do. It is dishonest to hide the actual data points while showing artificially even points instead. It misleads the viewer as to where the curve is reliable and where it may not be.

Ethan
  • 13,715
  • 2
  • 12
  • 21
  • Thank you very much, that is exactly what I was looking for. Regarding your objection about the questionable credibility of interpolated values: There is nothing dishonourable here. It is neither measured nor simulated data. The uneven distribution has only technical reasons. – scinopode Feb 04 '22 at 21:51
  • Great. Please mark it "accepted" so that it shows up as an answered question. – Ethan Feb 05 '22 at 00:21