How to plot data without a separate file by specifying all points inside the Gnuplot script?

前端 未结 6 749
死守一世寂寞
死守一世寂寞 2020-12-02 20:19

My program generates bash scripts that call gnuplot. I don\'t want to have to make an extra file to store the data; is there any way I can explicitly call all of the values?

6条回答
  •  感动是毒
    2020-12-02 20:56

    Gnuplot 5.0.1 datablocks

    main.gnuplot

    $data << EOD
    1 1
    2 4
    3 9
    4 16
    EOD
    
    plot "$data" \
      with linespoints \
      title "my data"
    

    Convert to PNG:

    gnuplot -e 'set terminal png' -e 'set output "main.png"' main.gnuplot
    

    Output:

    This method is a bit more versatile than '-' as it makes it easier to reuse the same data multiple times, including on the same plot command: How to embed multiple datasets in a gnuplot command script for a single plot command?

    Version 5 is available on Ubuntu 15.04, or compile from source with: https://askubuntu.com/a/684136/52975

    You may also be interested in the + and ++ special file names when plotting with functions.

    Tested on Ubuntu 18.10, gnuplot 5.2.

提交回复
热议问题