Menu

#385 Use a variable/function (after "with") to determine the type of graph.

None
closed-out-of-date
nobody
None
5
2014-05-22
2014-04-07
leoking
No

Here is an example of what I mean:

plot for [i=1:100] '-' title title(i) with with(i)

This feature is particular useful when drawing a figure with lots of series.

Discussion

  • Ethan Merritt

    Ethan Merritt - 2014-04-07
    • Group: -->
     
  • Ethan Merritt

    Ethan Merritt - 2014-04-07

    That makes no sense at all. Perhaps you are confusing "with" with some other keyword?

    The possible values for "with" are plot styles like "lines", "histograms", "boxplot", etc. Each of these requires a different set of input values.

    Nevertheless if you really want to put the plot style in a variable you can do that using macros:
    set macro
    with(n) == 1 ? "lines" : with(n) == 2 ? "points" : "impulses"
    style = with(n)
    plot FOO with @style

    This won't work in the kind of loop you showed, however.

     
    • leoking

      leoking - 2014-04-07

      Thanks for the reply. I really mean the actual "with".

      Macro does not work here cause it is only interpreted statically before execution.

      I think this feature is really useful when you are plotting many series in a same plot. You can then use a function to dynamically decide the plot styles (points, lines, linepoints, etc..).

      Here is a typical scenario:

      You want to plot 30 series in a same plot from a datafile. The datafile is in such a format:
      Series 1: results estimated from method1 on day 1
      Series 2: results estimated from method2 on day 1
      Series 3: results from actual measurement on day 1
      Series 4: results estimated from method1 on day 2
      Series 5: results estimated from method2 on day 2
      Series 6: results from actual measurement on day 2
      .....
      You want to plot results estimated from method1 using lines, that from method2 using linepoints. And plot results from actual measurement using points.

      If "with" supports function input, this scenario can be accomplished as:

      title(i)=value(sprintf("title%i",i mod 3))
      title0='method1'
      title1='method2'
      title2='measurement'

      with(i)=value(sprintf("with%i",i mod 3))
      with0='lines'
      with1='linepoints'
      with2='points'

      plot for [i=1:30] '-' title title(i) with with(i) ls i

      Besides, I am using java to general gnuplot code. The lack of ability to use variables/function to represent the with type of a series in a plot is now the only problem preventing me to create a flexible gnuplot code template.

       
  • Ethan Merritt

    Ethan Merritt - 2014-04-07

    This is already possible for the subset of styles lines and points. For other styles I don't think it makes any sense.

     set linetype 1 lc rgb "black" pt 0
     set linetype 2 lc rgb "blue" lw .01 pt 7
     set linetype 3 lc rgb "cyan" pt 7 pi -4 lw 2
    
     set sample 20
     plot for [i=1:10] (x-i) with linespoints lt (1 + i%3) title "".i
    
     
    • leoking

      leoking - 2014-04-07

      Thanks for the reply.

      It is really useful. I did not know that.

      Thanks.

       
    • leoking

      leoking - 2014-04-08

      I found a serious problem for this approach.

      If you set the linewidth of the linepoints type to mimic the option of "with points". The number of available point types that can be seen is then only 5. Only these filled point types (5, 7, 9, 11, 13) can be seen. All other point types can not be seen when the linewidth is set to be very small.

      Is there a way to work around?

       
  • Ethan Merritt

    Ethan Merritt - 2014-04-08

    Clean separation of all of the line/point properties is one of the issues being worked on for version 5. In fact it's the major issue holding up the release. So while I can tell you that there will be several ways to do this in version 5, they aren't available in current versions.

    For certain terminal types you could fix this locally. For instance, you could add a line in the local PostScript prologue.ps file that would make the linewidth used for drawing points separate from the one used for the lines.

    On the other hand, even with the current imperfect implementation a huge number of distinct linetypes can be defined and used. See for instance the last demo plot in
    http://gnuplot.sourceforge.net/demo/dashcolor.html

     
    • leoking

      leoking - 2014-04-08

      Thanks for the reply again. I always love & believe in gnuplot because of you guys.

       
  • Ethan Merritt

    Ethan Merritt - 2014-05-22
    • status: open --> closed-out-of-date
     

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.