2

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 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

In order to determine the number of curves, use the following (requires 4.6): 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.
Using 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.
Right, but in an other question the OP said he is working on MacOSX. And, again one can use python or perl to achieve the same: perl -pe 's/^$/\n/' data.txt

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.