How to plot several datasets with titles from one file in Gnuplot?

前端 未结 5 1855
心在旅途
心在旅途 2020-12-04 18:28

Assuming I have a file that looks like this:

\"p = 0.1\"
1 1
3 3
4 1


\"p = 0.2\"
1 3
2 2
5 2

Is it possible to make Gnuplot plot these tw

5条回答
  •  感动是毒
    2020-12-04 18:46

    This is Bruce_Warrior's and Ciro Santilli's answers but without the intermediate stats:

    # plot.gpi
    datafile = ARG1
    plot for [i=0:*] datafile index i using 1:2\
    with lines title columnheader(1)
    

    The for loop can iterate over all datasets in a file directly. It works in gnuplot 5.0.5 but I'm not sure when for acquired this capability. It is documented in the 5.0 manual but not the 4.6 manual.

    Unless the line color should be determined by a third input column consumed by linecolor variable (per Bruce's answer), gnuplot will assign different colors and line styles automatically. In this specific case using 1:2 can also be omitted.

    $ gnuplot --version
    gnuplot 5.0 patchlevel 5
    $ gnuplot --persist -c plot.gpi test.dat
    

    test.dat is

    "p = 0.1"
    1 1
    3 3
    4 1
    
    
    "p = 0.2"
    1 3
    2 2
    5 2
    

提交回复
热议问题