Coloring plot by x value
damianjwilliams
I'd like to color a graph by the x value but struggling to do it. I can easily color by y value using something like:
ModifyGraph zColor(test)={test,*,*,Rainbow,0}
but is it possible to do it for using the x value?
I can get close(ish) by manually coloring each point, but that doesn't work for lines between points. e.g.
Function rainbow_x()
//Much of this code is taken from the 'colorize traces demo' experiment
variable numpoints
ColorTab2Wave Rainbow
Make/O/N=120 test; SetScale x 0, 2*PI, test; test = sin(x)
Display/N=Rainbow_plot test
ModifyGraph/W=Rainbow_plot mode=3,marker=19,msize=1
numpoints = numpnts(test)
if (numpoints <= 0)
return -1
endif
Variable denominator= numpoints-1
if( denominator < 1 )
denominator= 1
endif
Wave rgb = M_colors
Variable numRows= DimSize(rgb,0)
Variable red, green, blue
Variable i, index
for(i=0; i<numpoints; i+=1)
index = round(i/denominator * (numRows-1))
ModifyGraph/W=Rainbow_plot rgb(test[i]) = (rgb[index][0], rgb[index][1], rgb[index][2])
endfor
End
//Much of this code is taken from the 'colorize traces demo' experiment
variable numpoints
ColorTab2Wave Rainbow
Make/O/N=120 test; SetScale x 0, 2*PI, test; test = sin(x)
Display/N=Rainbow_plot test
ModifyGraph/W=Rainbow_plot mode=3,marker=19,msize=1
numpoints = numpnts(test)
if (numpoints <= 0)
return -1
endif
Variable denominator= numpoints-1
if( denominator < 1 )
denominator= 1
endif
Wave rgb = M_colors
Variable numRows= DimSize(rgb,0)
Variable red, green, blue
Variable i, index
for(i=0; i<numpoints; i+=1)
index = round(i/denominator * (numRows-1))
ModifyGraph/W=Rainbow_plot rgb(test[i]) = (rgb[index][0], rgb[index][1], rgb[index][2])
endfor
End
Is there something obvious I'm missing? Thanks
In your ModifyGraph command, you are using the Y wave as the color as f(z) wave. You should be able to use any wave at all, as long as it has the right number of points. And "the right number of points" can be achieved using a wave subrange.
If you want arbitrary colors, you can use a 3- or 4-column wave with RGB or RGBA values.
July 12, 2021 at 03:55 pm - Permalink
In reply to In your ModifyGraph command,… by johnweeks
Ahhhh. It is very simple. Thanks.
Make/O/N=(numpnts(test)) fzwave = p
Display/N=colored_plot test
ModifyGraph/W=colored_plot zColor(test)={fzwave,*,*,Rainbow}
July 13, 2021 at 01:08 pm - Permalink