gnuplot generate plot command with sprintf?

前端 未结 1 423
醉话见心
醉话见心 2021-01-07 02:09

I want to generate a gnuplot plot command programmatically, like:

plotline = sprintf(\"\'datafile1.dat\' using %d:3 with points, \'%s\' using %d:3 with point         


        
相关标签:
1条回答
  • 2021-01-07 02:53

    In order to construct such a plot command from some strings, you can use eval to execute the commands contained in a string:

    plotline = 'x title "mytitle"'
    eval('plot '.plotline)
    

    Alternatively you can use set macros:

    set macros
    plotline = 'x title "mytitle"'
    plot @plotline
    

    This replaces @plotline with the content of the string variable plotline before executing the command. Using plot plotline interpretes the content of plotline as file name. Note, that as of version 4.6 macros don't work properly in loops, but eval works fine.

    BTW: If you don't specify your own title, then the actual plot statement is written in the plot legend. But that can't be written to the terminal output.

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