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
    Commented Sep 25, 2019 at 14:21
  • $\begingroup$ @kglr as far as I can tell your suggestion indeed works. Why not make it an answer? Thanks :) $\endgroup$
    – Tom
    Commented Sep 25, 2019 at 14:49
  • $\begingroup$ Tom, posted the comment as an answer. $\endgroup$
    – kglr
    Commented Sep 25, 2019 at 15:17

1 Answer 1

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 and acknowledge you have read our privacy policy.

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