4

Having data as:

38 52.26
41 46.34
42 49.49

Using smooth lines; can I include the points on the graph line without plotting it twice?

Now I use:

plot "foo.dat" using ($0):2 smooth csplines title "foo", \
               '' using ($0):2 with points title ""

Sample graph

Extended simplified data set:

38     52.26
39     46.34
42     57.29
43     60.41
44     53.57
45     51.49
46     48.24
49     58.50
50     56.85
51     55.56
52     62.81
54     51.76
55     46.94
56     46.35
57     52.76
59     49.49
62     51.78
63     48.24
65     54.46
66     50.00
4
  • 1
    You could try with linespoints, but I'm not sure if that would do what you want. (I'd need a full datafile to experiment with it). Is there anything wrong with the extra line of code? In other words, do you want your plot to look differently? If yes, what would you want to change about it? We might be able to work with that if you give more detail about what you're looking for.
    – mgilson
    Commented Dec 17, 2012 at 16:08
  • @mgilson: Yes with linespoints is not what I want as that set points at given point interval - and not at "data points". It is nothing wrong with "that extra line" but wondered if there was a cleaner/more correct way to do it.
    – Luca Stein
    Commented Dec 17, 2012 at 17:06
  • In that case, I would say that there is not a cleaner way to do it (other than to say '' using ($0):2 with points notitle instead of title "" for the second plot.)
    – mgilson
    Commented Dec 17, 2012 at 17:33
  • @mgilson: OK. Thank you. Add it as an answer and I'll accept :) (P.s.: the "Extended simplified data set" was a bit stupid as column 1 is not consecutive. (It is typically 1 2 4 7, not 1 2 3 4 5 6 7). - edited now for ref.) The notile was good - title "" looks more as a hack and is ambiguous in code.
    – Luca Stein
    Commented Dec 18, 2012 at 4:37

1 Answer 1

7

This is my way to do it:

...
plot "file" using 1:3 notitle with points linestyle 1, \
     "" using 1:3 notitle smooth csplines with lines linestyle 1, \
     1 / 0 title "title" with linespoints linestyle 1
...

enter image description here

The first entry plots the points on the graph, without a legend. The second entry plots the smoothed line on the graph, again without a legend. The third entry is just for the legend, using the combined linespoints.

If you use linespoints on the smoothed line, it will show all the points making it smooth, not just the datapoints.

'linestyle' tells gnuplot to plot all the data using the same style, basically compositing the lines and the points to make linespoints. The third line, the 'linespoints', is just for the legend, and does not put any data on the plot.

1
  • 4
    Regardless of if this works or not, please try to also include some explanation with your code. A high quality answer will not only give a solution but explain how it works / why you do it that way. Commented Oct 30, 2013 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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