Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Column names in lieu of column numbers

Help
2005-05-11
2013-02-10
  • Dennis Keller
    Dennis Keller
    2005-05-11

    Is there a way in gnuplot to use column names (titles) from a datafile for use with gnuplot.  For
    example

    sample.dat contents follow:

    ## TIME ALTITUDE ROLL ALPHA
    0.0 2300.0 3.0 20.0
    10.0 2200.0 2.5 18.5
    20.0 2100.0 2.25 18.2
    30.0 2000.0 2.0 18.0

    Normally you would say
    >plot "sample.dat" using 1:2
    to plot ALTITUDE versus TIME

    I would like to something a bit like
    >plot "sample.dat" using name TIME,ALTITUDE

    This is extremely useful for flight simulation data
    where you have a very large number of columns and
    don't know ahead of time what column # contains what data but do know the variable's name you want
    to plot.  I would be disappointed if gnuplot does
    not support this feature.

    HELP!

    Dennis

     
    • There's no such feature built into the program, but it's reasonably easy to put it in using external tools, if you're on a sane platform.  Write an awk/perl/whatever script that takes the first line of the data file and outputs a sequence of variable settings:
      c_TIME=1
      c_ALTITUDE=2
      [...]

      then run this program to evaluate the output inside gnuplot:

            gnuplot> `yourscript datafile`

      (note the back quotes).  Then you can

            gnuplot> plot 'datafile' using c_TITLE:c_ALTITUDE

      Expanding on this idea, you can generate the entire plot command line by such an external tool, and/or have the external tool call gnuplot, instead of the other way round.

       
    • Dennis Keller
      Dennis Keller
      2005-05-12

      I guess this a basic solution, but I wanted to
      have the names tied to the actual data values
      (as an array).  This way I could perform math
      ( altitude+runway_alt) or print out values for
      each variable (print alpha, roll).  If anyone has found
      a solution via scripts, I would love to get a copy
      of this script.  I cannot believe that gnuplot does
      not have a direct method to plot via names.  There
      are so many smart people working on this software and nobody has thought about this at all?

       
      • You seem to be mixing up concepts here.

        gnuplot uses data files in only two kinds of command:
        'plot' (including splot and replot), and 'fit', and those use it almost exactly the same way.  They loop over the entire file and do something with every "record" (line of text, roughly).  In this, and *only* in this context, do column numbers have any significance whatsoever: they give access to individual fields of that record.

        You can perform math as part of the plot/fit command just fine:

        # run a script like the one I proposed earlier
        plot 'data'\ using  c_alt:(column(c_windx)*column(c_foo))

        gnuplot is not meant to be a spreadsheet calculator or something like that, though.  I.e., for more elaborate fudgings like that, sooner or later you'll reach the point where you need a different tool.

         
    • Dennis Keller
      Dennis Keller
      2005-05-13

      I don't want to sound like I am not gratefull for
      some type of response to my query, but your answers are not adequate.  I already have (using)
      a simulation plot package (written with FORTRAN
      and a small amount of C) which already does
      whatt I am asking for in gnuplot.  We have asked to find a open source solution, since NASA does not want to support any more development.  Our
      plot package does support a limited number of
      math and functions on the actual data.

      Often we are so close to a software that we don't see what the user's need to solve their problems
      (can't see the forest for the trees getting in the way).  Maybe column names is not the correct way to state this issue.  This is actually a variable assigmment (table variable name) given to each of the columns of data.  These could be treated just like normal functions that can be defined inside of gnuplot.

       
      • Did it occur to you that the cause for what you perceive as inadequate answers might have been that you asked rather unclear questions?  Please keep in mind that you're at least as guilty of silently assuming context as I am, here.  What you may have available to you in addition to gnuplot, or what NASA does or does not want to support is completely beside the point of this discussion. I can't know what "your plot package" does, nor do I think I should have to.

        What is the issue here is what gnuplot can, or can not do.  Current gnuplot has no support whatsoever for array variables, so a column of data taken from some file cannot be a gnuplot variable.  If you're looking for a Matlab replacement, i.e. a program for large-scale data manipulation and vector data handling, gnuplot is not it.  Try Octave instead.

         
    • Dennis Keller
      Dennis Keller
      2005-05-20

      Did it occur to you that your responses were not expressed in a manner which could be considered by most to be friendly. Bottom line is gnuplot is not data file friendly...looks like a good match!