Menu

using word in a plot command

Help
2020-11-09
2020-11-10
  • Anglès d'Auriac

    Hello

    I have a file 'tmptst('with two data-sets and the following script

    cols = "red blue"
    styles = "linesp linesp"
    wids = "1 4"
    plot for [i=1:2]  'tmptst' i i-1 lc rgb word(cols,i) lw word(wids,i) wi linesp ti sprintf("%d",i) # OK
    plot for [i=1:2]  'tmptst' i i-1 lc rgb word(cols,i) lw word(wids,i) wi word(styles,i) ti sprintf("%d",i) # NON OK
    

    the first plot (line 4) is fine (title, color, style and width) are OK,
    but the second is not: " line 5: unrecognized plot type"
    What is wrong on line 5 ?
    Thank you

     
  • Hans-Bernhard Broeker

    Your problem is that in line 5 you're trying to use the string not just as a parameter to some keyword, but as the keyword itself. The test case can be simplified to

    gnuplot> plot sin(x) lc rgb "blue" lw "2" w "linesp"
                                                        ^
             unrecognized plot type
    
    gnuplot> plot sin(x) lc rgb "blue" lw "2" w linesp   
    
     
  • Anglès d'Auriac

    Thank you Hans-Bernhard Broeker for your explanation.
    Indeed

    a="linesp"
    plot sin(x) lc rgb "blue" lw "2" w @a
    

    works, but

    plot sin(x) lc rgb "blue" lw "2" w @a
    

    and

    plot sin(x) lc rgb "blue" lw "2" w @word(a,1)
     plot sin(x) lc rgb "blue" lw "2" w sprintf("@%s",word(a,1))
     plot sin(x) lc rgb "blue" lw "2" w @sprintf("%s",word(a,1))
    

    do not work.

    So how can I switch between line, point and linesp in a plot for loop the choice between the 3 possibilities being determined by a string (like the colors eg) or possibly a function ?

     
  • Anglès d'Auriac

    oh sorry for a misprint : the first not working line is

    plot sin(x) lc rgb "blue" lw "2" w @"a"
    
     
    • Anglès d'Auriac

      https://stackoverflow.com/questions/63689746/gnuplot-setting-line-style-in-a-for-loop
      propose a solution using linespoints and a smart modification of the parameters.
      It works with fine Version 5.0 patchlevel 0 last modified 2015-01-01
      but not with Version 5.4 patchlevel 0 last modified 2020-07-13 (points never shown)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.