3

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$.

corey979
  • 23,947
  • 7
  • 58
  • 101
Saeid
  • 801
  • 4
  • 12

1 Answers1

2

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

corey979
  • 23,947
  • 7
  • 58
  • 101