2
$\begingroup$

I have a ColorFunction that I use to color a Plot, with the option ColorFunctionScaling -> False so that the ColorFunction uses the literal x-axis values.

f[x_] := Blend[{Blue, Red}, Cos[x]^2];
Plot[x, {x, 0, 4 Pi}, ColorFunction -> (f[#1] &), ColorFunctionScaling -> False]

Output plot from above code

I want to modify this code so that it works similarly for a log-scale plot. Specifically LogLinearPlot, but a general approach for all of its log cousins would be good. Modifying the above code with the substitution Plot -> LogLinearPlot produces the error:

Image of error code displayed

And also a plot, but I don't think the ColorFunction has worked properly.

$\endgroup$
3
  • 1
    $\begingroup$ Maybe using the option ScalingFunctions: e.g. instead of LogLinearPlot we can use Plot[x, {x, 0.001, 4 Pi}, ColorFunction -> (f[#1] &), ColorFunctionScaling -> False, ScalingFunctions->{"Log",None}]? $\endgroup$
    – kglr
    Sep 25 '19 at 14:21
  • $\begingroup$ @kglr as far as I can tell your suggestion indeed works. Why not make it an answer? Thanks :) $\endgroup$
    – Tom
    Sep 25 '19 at 14:49
  • $\begingroup$ Tom, posted the comment as an answer. $\endgroup$
    – kglr
    Sep 25 '19 at 15:17
2
$\begingroup$

Using Plot with the option ScalingFunctions ->{"Log", None}:

f[x_] := Blend[{Blue, Red}, Cos[x]^2];

Plot[x, {x, 0.001, 4 Pi}, ColorFunction -> (f[#1] &), 
 ColorFunctionScaling -> False, ScalingFunctions -> {"Log", None}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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