x = (0:80)/80; y = @.sin(3*exp(x)); using Plots cg = cgrad(:viridis,range(0,stop=1,length=64)) plot(x,y,line_z=y,color=cg)
What I get (this is GR, but other backends seem to be similar):
This is not what I expected. I thought the
line_z parameter would be used to index within the color gradient, giving colors like this:
[RGB(cg[y]) for y in y]
All the negative values are “clipped” to the deep purple.
It seems that in the plot, the supplied color values are affinely mapped to use the full range of the color gradient. I find that counterintuitive, as I expected the gradient to define a fixed/absolute mapping to color values. I’ve searched unsuccessfully for a keyword or toggle that gives this behavior. What am I missing?
(I find this pretty important behavior for a sequence or animation in which I want colors to have fixed interpretations in time.)