I have the x,y data for a number of curves stored in one file, separated by a blank line. I want to plot the different curves with different line styles (solid, dashed ...). How do I do it ?
1 Answer
You can use the every keyword to select block of datas (separated with a single empty line, so two new line character after each other), and you can use the linestyle keyword to explicitely define linestyle.
p "data.txt" every:::0::0 w l ls 1, "" every:::1::0 w l ls 2
If you have not so much datas, you can write the whole command by hand. If you have more block of datas, you may prefer to use a for loop:
p for [i=0 : maximum_number_of_curves : every_nth_curve] "data.txt" every:::i::i w l ls i
Please note that some terminal types does not support dashed or dotted linestyles. Use 1 as the value of every_nth_curve if you would like to use every data.
If you have double empty lines (three new line characters), you have to use the index keyword to select block of datas, e.g:
p for [i=0 : maximum_number_of_curves : every_nth_curve] "data.txt" index i w l ls i
3 Comments
stats '< sed ''s/^$/\n/'' data.txt' nooutput; maximum_number_of_curves = int(STATS_blocks)-1. The sed command replaces a single empty row by two empty rows, so that each curve is considered as an own data set, which is then counted with STATS_blocks.sed is a great idea but please note that it is not available on every PC however it is free for use under GNU license.python or perl to achieve the same: perl -pe 's/^$/\n/' data.txt