4
$\begingroup$

I like the way AbsArgPlot uses a default ColorFunction that cycles through the hues with much less variation in perceived brightness than just using Hue[h,1,1]. To illustrate:

psi = Exp[-x^2] Exp[10 I x];
AbsArgPlot[psi Abs[psi], {x, -3, 3}, Filling -> Axis]

AbsArgPlot output

Compare to doing it manually using Hue[]:

 Plot[Abs[psi]^2, {x, -3, 3}, PlotPoints -> 200, Filling -> Axis, 
 ColorFunction -> Function[x, Hue[Arg[psi]/(2 Pi)]], 
 ColorFunctionScaling -> False]

Plot output that mimics AbsArgPlot using Hue

So I'm wondering how to use and/or adapt and/or mimic the default AbsArgPlot ColorFunction in other code. I'd especially like to come up with something similar that fades out to white as Abs[f] goes to zero, for use with RegionPlot in examples like this:

psi = Exp[-(x^2 + y^2)]*Exp[5 I (x + y)];
RegionPlot[True, {x, -2, 2}, {y, -2, 2}, 
ColorFunction -> Function[{x, y}, Hue[Arg[psi]/(2 Pi), Abs[psi]^2, 1]], 
ColorFunctionScaling -> False, PlotPoints -> 100]

RegionPlot of a complex-valued function of two variables

Of course, I could fool around with formulas for saturation and brightness that depend on the Arg of the function, but obviously someone at Wolfram has already found formulas (or the equivalent) that work nicely. Any idea how I can get them? Any other suggestions?

$\endgroup$

1 Answer 1

6
$\begingroup$

The color function is a gradient "MidShiftBalancedHue":

Plot[Abs[psi]^2, {x, -3, 3}, PlotPoints -> 200, Filling -> Axis, 
 ColorFunction -> "MidShiftBalancedHue"]

enter image description here

This reproduces the ArgAbsPlot:

Plot[Abs[psi]^2, {x, -3, 3}, PlotPoints -> 200, Filling -> Axis, 
 ColorFunction -> (ColorData["MidShiftBalancedHue"][
     Rescale[Arg[Block[{x}, psi /. x -> #]], N@{-Pi, Pi}]] &), 
 ColorFunctionScaling -> False]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ I guess the Block[{x},...] isn't necessary. (Something messed up, I put in Block, and it got fixed. Must have fixed whatever it was accidentally. Hmm.) $\endgroup$
    – Michael E2
    Apr 17, 2022 at 17:33
  • $\begingroup$ Wow--thanks! I can't find anything about "MidShiftBalancedHue" in any Wolfram documentation, so I have to wonder how you know about it and whether it's something we can rely on working in the future. $\endgroup$
    – dvs
    Apr 17, 2022 at 18:05
  • 1
    $\begingroup$ @dvs (1) See mathematica.stackexchange.com/q/57885/4999, which reveals how these colors are managed. (2) The names for ColorData are stored in DataPaclets`ColorDataDump`colorSchemeNames; the data for this one may be found with Cases[DataPaclets`ColorDataDump`colorSchemes, {{"MidShiftBalancedHue", ___}, ___}] -- you could save it if you're worried about it going away. (3) I started with ? *`*ArgAbs* and use GeneralUtilities`PrintDefinitions on ...`iArgAbsPlot and followed the code. (4) Even documented things change or go away, but undocumented is riskier. $\endgroup$
    – Michael E2
    Apr 17, 2022 at 18:29

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.