akonsu
akonsu

Reputation: 29556

how to output dots/arrows at the ends of line

I am new to gnuplot, I need to plot my data and display a small circle or an arrow at each end of the line chart. how can I do that? I use this command to display the line chart:

plot 'data.txt' with lines

Upvotes: 1

Views: 595

Answers (1)

andyras
andyras

Reputation: 15920

I don't know if there is a way to make lines have something at the end automatically, but I found a workaround. With this data file:

1 1
2 3
3 2

and the following script:

set term png
set out 'plot.png'

stats 'data.dat' name 'a'
# plot line, then circle only if it is the last data point
plot 'data.dat' t 'data', \
     '' u ($0==(a_records-1)?$1:1/0):2 with points pt 7 ps 2 t 'end'

I can make a plot like this:

enter image description here

The stats command is to find the number of data points, then the dual plot command draws the line connecting the data points, then a circle only on the last data point (determined with the a_records variable. An arrow would be trickier to draw...

To find more info about different point/line style options, the test command at the gnuplot command line is your friend.

Upvotes: 1

Related Questions