0
$\begingroup$

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};
int = Interpolation[grad];
cf = Function[{x, f}, ColorData[{"AvocadoColors", {0, n}}][int[x]]];
cf2 = ColorData[{"AvocadoColors", {0, n}}] /@ grad;
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)?

$\endgroup$
0

1 Answer 1

1
$\begingroup$
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]]];
 
cf2 = ColorData[{"AvocadoColors", {0, 10}}] /@ grad;
 
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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.