Plot all files in a directory simultanously with gnuplot?

前端 未结 4 2117
梦如初夏
梦如初夏 2020-12-17 19:34

I want to do something similar to this question: gnuplot : plotting data from multiple input files in a single graph.

I want to plot simultaneously all the

相关标签:
4条回答
  • 2020-12-17 19:46

    You could try something like:

    a=system('a=`tempfile`;cat *.dat > $a;echo "$a"')
    plot a u 3:2
    

    This uses the command line tempfile command to create a safe, unique, and disposable temporary file. It mashes all of the data files into this file. It then echoes the file's name so gnuplot can retrieve it. Gnuplot then plots things.

    Worried about header lines? Try this:

    a=system('a=`tempfile`;cat *.dat | grep "^\s*[0-9]" > $a;echo "$a"')
    

    The regular expression ^\s*[0-9] will match all lines which begin with any amount of whitespace followed by a number.

    0 讨论(0)
  • 2020-12-17 19:50

    I like to be able too choose the files to plot with wildcards, so if you like that you can do as follows, though there are many ways. Create the following script.

    script.sh:

    gnuplot -p << eof
    set term wxt size 1200,900 title 'plots'
    set logs
    set xlabel 'energy'
    plot for [ file in "$@" ] file w l
    eof
    

    do chmod u+x script.sh

    Run like ./script.sh dir/* *.dat

    If you need it often make an alias for it and put it in some reasonable place:) Cheers /J

    0 讨论(0)
  • 2020-12-17 20:01

    As an alternative to Jonatan's answer, I would go with

    FILES = system("ls -1 *.dat")
    plot for [data in FILES] data u 1:2 w p pt 1 lt rgb 'black' notitle
    

    or

    plot '<(cat *.dat)' u 3:2 title 'your data'
    

    The first option gives you more flexibility if you want to label each curve. For example, if you have several files with names data_1.dat, data_2.dat, etc., which will be labeled as 1, 2, etc., then:

    FILES = system("ls -1 data_*.dat")
    LABEL = system("ls -1 data_*.dat | sed -e 's/data_//' -e 's/.dat//'")
    
    plot for [i=1:words(FILES)] word(FILES,i) u 3:2 title word(LABEL,i) noenhanced
    
    0 讨论(0)
  • 2020-12-17 20:04

    Try the following command:

    gnuplot -e 'plot for [file in system("find . -depth 1 -type f -print")] file u 3:2'
    

    Note: Add -p to keep the plot window.

    0 讨论(0)
提交回复
热议问题