3
$\begingroup$

I'd like to use scientific notation for the bar legend. I tried to follow the approach of this link: Number format in Legend Labels.

However, the LegendFunction did not work for my case (or, maybe, I did not use it correctly). The simple code, without any LegendFunction, is

DensityPlot[10^-4 Exp[(-x^2 - y^2)], {x, -2, 2}, {y, -2, 2}, 
PlotPoints -> 60,
ColorFunction -> Hue, FrameLabel -> {"x", "y"}, 
LabelStyle -> {Bold, Black, FontSize -> 12}, 
FrameStyle -> Directive[Black, 12], PlotLegends -> Automatic]

The output plot is here:

enter image description here

But for the bar legend I prefer scientific notation, like $2.0\times 10^{-5}$ (but not $2.0000\times 10^{-5}$) instead of $0.00002$.

$\endgroup$
2
$\begingroup$

From the referenced thread:

f[x_] := x /. {NumberForm[y_, {w_, z_}] :> ScientificForm[y, 2]}

DensityPlot[10^-4 Exp[(-x^2 - y^2)], {x, -2, 2}, {y, -2, 2}, 
PlotPoints -> 60, ColorFunction -> Hue, FrameLabel -> {"x", "y"}, 
LabelStyle -> {Bold, Black, FontSize -> 12}, 
FrameStyle -> Directive[Black, 12], 
PlotLegends -> {LegendFunction -> f}]

enter image description here

or

f[x_] := x /. {NumberForm[y_, {w_, z_}] :> ScientificForm[NumberForm[y, {2, 1}], 2]}

to get

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.