Menu

shuffling color label

2016-02-02
2016-03-15
  • Masahiro Takahashi

    Hi,

    I want to randomly change color of the plot.
    In MATLAB I found using label2rgb with option 'shuffle'
    http://blogs.mathworks.com/steve/2012/05/15/shuffling-label-colors/

    Is there a way to do it in gnuplot?

    [detail]
    I have data with 4 colums: x, y, z, label.
    'label' is integer and increases one by one.
    I would like to shuffle 'label' when it is plotted:
    sp 'file' u 1:2:3:4 lc palette

    Thanks,
    masa

     
  • Ethan Merritt

    Ethan Merritt - 2016-02-02

    I don't understand what you mean by "shuffle", and I don't know what the meaning of "label" is. But...

    If you want to use a random palette color for each point you can do:

    splot 'file' using 1:2:3:(rand(0)) with points lc palette z
    
     
    • Masahiro Takahashi

      Thanks for your reply.

      What I want to do is following (let me clarify my question by 2D plot):

      prepare 'data.txt':
      1.0 2.0 1
      2.0 3.0 1
      3.0 4.0 1

      1.0 2.5 2
      2.0 3.5 2
      3.0 4.5 2

      1.0 4.5 3
      2.0 3.5 3
      3.0 2.5 3

      The following command plot as it is:
      pl 'data.txt' u 1:2:3 w lp lc palette

      I want to do something shuffling (switching) the 3rd column randomly,
      so I plot the data as
      1.0 2.0 1*rand() (=3?)
      2.0 3.0 1*rand() (=3?)
      3.0 4.0 1*rand() (=3?)

      1.0 2.5 2*rand() (=1?)
      2.0 3.5 2*rand() (=1?)
      3.0 4.5 2*rand() (=1?)

      1.0 4.5 3*rand() (=2?)
      2.0 3.5 3*rand() (=2?)
      3.0 2.5 3*rand() (=2?)

      I want to do something like the 3rd and 4th plot of following web site:
      http://blogs.mathworks.com/steve/2012/05/15/shuffling-label-colors/

      Is it possible?

       

      Last edit: Masahiro Takahashi 2016-02-03
  • Ethan Merritt

    Ethan Merritt - 2016-02-03

    Sorry, I do not understand.
    Coloring by palette implies a continuous variable between 0.0 and 1.0
    Coloring by discrete integers is something else entirely.

    If you want a random palette color for the data points given above, then use

    plot 'data.txt' using 1:2:(rand(0))  with points pointsize 5 lc palette
    

    Using randomly colored lines is usually confusing, but points work OK.

     
    • Masahiro Takahashi

      Ummm, sorry for my bad explanation.

      What I attached is a figure produced by
      splot 'data.txt' using 1:2:3:4 w l lc palette

      I would like to change the color of rings randomly.
      Is there a way to do that in inside the gnuplot?
      Or do I need to shuffle the label when I produce data file?

      p.s.1
      I understand palette is for continuous color changes.
      But in my case, the number of rings are huge and the labeling is almost continuous in other data.

      p.s.2
      plot 'data.txt' using 1:2:(rand(0)) with points pointsize 5
      gives me the same color plot. Is it correct?
      I'm using newest version of gnuplot.

       

      Last edit: Masahiro Takahashi 2016-02-03
  • Ethan Merritt

    Ethan Merritt - 2016-02-03

    Oops. I clicked the "delete" button rather than the "download" button, so I lost your pdf plot.

    Still not sure I understand, maybe this will help...
    The "index" keyword selects one block of data from your file. The index number is (I think) the same thing you have in column 4 of the data. So this command should give you a distinct line color for each indexed block:

    splot for [i=1:*] 'data2.txt' index i using 1:2:3 lc i
    

    This is not palette coloring. It uses the normal sequence of colors by linetype. The iteration using a star symbol to mean "until end of file" is only supported in the CVS version of gnuplot, so I hope that is what you mean by "newest". Otherwise you could say for [i=1:999] but you may get an error message for every iteration with i beyond the end of the file.

    To add randomness you could replace "lc i" with some other constant color. Do not use the 'palette' keyword because that is not a constant. Maybe something like this to generate RGB colors with random components R G B.

       RGB(r,g,b) = sprintf("#%06x",256.*256.*255.*r+256.*255.*g+255.*b)
       splot for [i=1:*] 'data2.txt' index i using 1:2:3 lc rgb RGB(rand(0), rand(0), rand(0))
    
     
  • Ethan Merritt

    Ethan Merritt - 2016-02-04

    I thought of a way to use random colors drawn specifically from the palette

      splot for [i=1:*] color=rand(0) 'data2.txt' index i using 1:2:3:(color) lw 4 lc palette
    

    This works because the color definition is executed only once per iteration, and the resulting value is then treated as a constant palette color

     
    • Masahiro Takahashi

      Sorry for my replay.
      Thanks for your answer.

      This is what I wanted to do!
      Thank you!

       
  • Lucy Thiele

    Lucy Thiele - 2016-03-03

    Ummm, I don't understand either

     
    • Masahiro Takahashi

      Sorry my bad explanation...

       

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.