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

前端 未结 5 1854
心在旅途
心在旅途 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:35

    gnuplot 5.1 (2016/08/28)

    This is similar to https://stackoverflow.com/a/29495496/895245 but with some fixes for later versions.

    https://stackoverflow.com/a/43819870/895245 taught me the for [i=0:*] syntax which dispenses stats and is therefore a bit nicer.

    Script:

    datafile = 'test.dat'
    stats datafile nooutput
    plot for [IDX=0:STATS_blocks-1] \
        datafile \
        index IDX \
        using 1:2 \
        with lines \
        title columnheader(1)
    

    Test data:

    a
    1, 1
    2, 2
    3, 3
    
    
    "b"
    1, 1
    2, 4
    3, 9
    
    
    "c, c"
    1, 1
    2, 8
    3, 27
    

    Output:

    This works on gnuplot 2016/08/28 which will later become gnuplot 5.1, but not in gnuplot 5.0.3 (Ubuntu 16.04), because in 5.0.3 the stats command gives an error because the column headers are not valid data. And on 2016/08/28 it became just a warning.

    I've asked how to remove the warning at: https://groups.google.com/forum/#!topic/comp.graphics.apps.gnuplot/Pi4aBE2PwZ8

    Using comments like:

    #a
    1, 1
    2, 2
    3, 3
    

    did not work in either version I've tested, it is just ignored.

提交回复
热议问题