# Plot a line colored set by value of a different list

I have a model, see code below:

n = 10;
lis = Table[i^4, {i, 0, 1, 1/n}];
grad = {1, 1, 9, 9, 9, 9, 9, 9, 10, 10, 10};
cf = Function[{x, f}, ColorData[{"AvocadoColors", {0, n}}][int[x]]];
g1 = ListLinePlot[lis, ColorFunction -> cf, ColorFunctionScaling -> False]
g2 = ListLinePlot[lis, ColorFunction -> cf2, ColorFunctionScaling -> False]
g3 = ListLinePlot[Table[{i, i^4}, {i, 0, 1, 1/n}], ColorFunction -> cf2, ColorFunctionScaling -> False]


I have tried coloring "lis" using the values in grad. for some reason, the method in g2 (using cf2) is not working and in g1 it is great (using cf) and that is the result I'm looking for. the problem is that in g3, when I'm trying to plot "lis" and scale the x-axis interpolation is not working well, how can I fit the results so g3 would be colored as g1 (using cf and not cf2)?

lis[n_] := Refine[
Table[i^4, {i, 0, 1, 1/n}], {Element[n, Reals], n > 0}];

$Assumptions = grad > 0 && Element[grad, Reals]; grad = {1, 1, 9, 9, 9, 9, 9, 9, 10, 10, 10}; int = Interpolation[grad];$Assumptions = x > 0 && Element[x, Reals];

cf = Function[{x, f}, ColorData[{"AvocadoColors", {0, 10}}][int[x]]];

g1 = ListLinePlot[lis, ColorFunction -> cf,
ColorFunctionScaling -> False]
g2 = ListLinePlot[lis, ColorFunction -> cf,
ColorFunctionScaling -> False]
g3 = ListLinePlot[Table[{i, i^4}, {i, 0, 1, 1/n}],
ColorFunction -> cf,
ColorFunctionScaling -> False]


g3 now varying colored

• I did not understand what is the change so that g3 is colored using "cf". what is the line that allows it? Commented May 23, 2021 at 22:07
• @jonathan the key lines are the uses of ColorFunction and ColorFunctionScaling Commented Jun 22, 2021 at 13:32