Menu

Trying to use 4 column data for splot

Help
2025-04-14
2025-04-16
  • Randall L Rathbun

    I am trying to use splot to display 3 dimension data, with a colorspec in the 4th column.
    For example, the first three lines of my "data" file read:

    33.152 116.649 0.6 "0xFF0000"
    33.150 116.654 0.8 "0xFD0402"
    33.152 116.649 0.5 "0xFB0804"

    The 4th column is a 24 bit RGB color value.
    I have tried to set up the appropriate splot command, but I have been unable to get the plot line to satisfactorily display the data

    % splot "data" using 1:2:3:4 with dots lw 5 rgbcolor variable

    for example
    What would be the correct way to do the splot line?

    Thank you for your help.

     
    • Hiroki Motoyoshi

      I think your plot isn’t working as expected due to two key points that need a small adjustment.

      1. Use of "rgbcolor variable":
      To specify point colors, you should use the linecolor option (abbreviated as lc) together with "rgbcolor variable". So make sure your plot command includes something like:

      lc rgbcolor variable
      

      2. Handling of the fourth column in "using":
      In your data, the fourth column appears to be a hexadecimal color code in double quotes, like "0xFF0000". Gnuplot treats this as a string. However, when using "lc rgbcolor variable", Gnuplot expects a numeric color value (an integer).

      To fix this, you can explicitly convert the string to an integer using "int(strcol(4))", like this:

      splot "data" using 1:2:3:(int(strcol(4))) with dots lw 5 lc rgbcolor variable
      

      Alternatively, if you're generating the data yourself, it's even better to write the color codes as unquoted numeric literals:

      33.152 116.649 0.6 0xFF0000
      33.150 116.654 0.8 0xFD0402
      33.152 116.649 0.5 0xFB0804
      

      With that format, the following will work just fine:

      splot "data" using 1:2:3:4 with dots lw 5 lc rgbcolor variable
      

      Hope this helps.

       

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.