3
$\begingroup$

When using PlotLegends -> "Automatic" in ComplexPlot, it seems that Mathematica always picks some value different from 1 on the absolute value bar. See here (it picked the value 1.3):

ComplexPlot[z, {z, 1}, PlotLegends -> Automatic]

enter image description here

Is there a way I can make the value 1 appear on the absolute value bar instead (for any given plot when the function attains 1 in absolute value)? I couldn't find it in the official documentation of ComplexPlot.

$\endgroup$

1 Answer 1

2
$\begingroup$

Looking at the source code of ComplexPlot, it seems that the ticks are hardcoded in System`ComplexPlotsDump`parseShadingLegend, and cannot be easily and reliably changed by user. You can request the feature to the Wolfram Technical Support.

However, let's break down how Mathematica picks the value anyway. It turns out that the automatically chosen value is the $97.5 \%$ percentile of acquired absolute values of the function on the given domain* (calculated in System`ComplexPlotsDump`complexPlotRasterGenerate).

f[z_] := z;

domainGrid = 
  Catenate@Table[
    x + y I, {x, Subdivide[-1, 1, 144]}, {y, Subdivide[-1, 1, 144]}];
values = f /@ domainGrid;

Quantile[Flatten @ Abs @ values, 0.975] // N
(* 1.26785 *)

System`ComplexPlotsDump`makeNiceNumber[%]
(* 1.3 *)

Without patching the source code, we can modify the ticks with this auxiliary function:

changeLegendTicks[vals_] := 
 Function[cPlot, 
  cPlot /. {t1_, t2 : {p1_, v1_?NumberQ | NumberForm[v1_, __]}, 
     t3_} :> {t1, Sequence @@ ({Rescale[#, {0, v1}, {t1[[1]], p1}], #} & /@ vals), t3}]

plot = ComplexPlot[z, {z, 1}, PlotLegends -> Automatic, ImageSize -> 200];

Row[{
  plot, "     ",
  plot // changeLegendTicks[{0.1, 0.5, 1}]
  }]

ComplexPlot

Note that this is a "hacky way", and you should always check that the position of changed ticks is sensible.


*Domain is discretized into a grid with size RasterSize (144 by default, or 77 if PerformanceGoal -> "Speed", or whatever the user sets).

$\endgroup$
1
  • $\begingroup$ @Vestoo In your request to Wolfram Tech Support ask that ComplexPlot support the OpacityFunction and OpactityFunctionScaling options similar to DensityPlot3D support of these options. $\endgroup$
    – Edmund
    Mar 30 at 12:09

Your Answer

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

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