gnuplot how to give column number to plot dynamically?

前端 未结 3 1420
清酒与你
清酒与你 2021-01-15 15:33

I am automating a task to create small graphs using gnuplot. And I need to pass the column number from the datafile that is to be plotted

pfile=system(\"echo         


        
相关标签:
3条回答
  • 2021-01-15 16:04

    You could also pass the column number via command line

    gnuplot -e "colnum=$colnum" script.gp
    

    and your script.gp contains

    plot pfile using 4:(column(colnum))
    
    0 讨论(0)
  • 2021-01-15 16:06

    This is an alternative to @EWCZ's answer. Any variable initialized using the system command is treated as a string: in your case, colnum="2" (with quotes). You can transform it to an integer by adding zero:

    # first option
    plot pfile using 4:(column(colnum+0))
    
    # second option
    colnum = system("echo $colnum") + 0
    plot pfile using 4:(column(colnum))
    

    As a side note, your task could be more flexible (easier to automate) by using @Christoph's answer; better if you have gnuplot 5.0 because you can pass arguments to a gnuplot script directly

    0 讨论(0)
  • 2021-01-15 16:07

    it seems that one has to do colnum=int(system("echo $colnum")) so that the variable colnum is interpreted as an integer and not a string

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