4
$\begingroup$

Consider the following data and corresponding ListDensityPlot:

data = RandomReal[{0.0001, 0.0003}, {10, 10}];

ListDensityPlot[data, ColorFunction -> "SunsetColors", 
 ColorFunctionScaling -> True, 
 PlotLegends -> 
  BarLegend[Automatic, LegendLabel -> "Density", 
   LabelStyle -> Directive[Black, 14]]]

I want to make the legends bar of the form 1.3e-4,...,3e-4, while by default, it displays as 0.000125,...

enter image description here

Could you please tell me how to achieve this?

$\endgroup$
0

1 Answer 1

5
$\begingroup$

Based upon Number format in Legend Labels

form[x_] := 
   ReplaceAll[x, {NumberForm[y_, {w_, z_}] :> ScientificForm[y, 2]}]

data = RandomReal[{0.0001, 0.0003}, {10, 10}];

ListDensityPlot[data,
 ColorFunction -> "SunsetColors",
 ColorFunctionScaling -> True,
 PlotLegends -> {LegendFunction -> form, LegendLabel -> "Density", 
   LabelStyle -> Directive[Black, 14]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks! It works good, although in my version of Mathematica it shows 10 as $10^{1}$. $\endgroup$ Commented Jul 10 at 16:16
  • $\begingroup$ You're most welcome. Have a look at the option ExponentFunction $\endgroup$
    – eldo
    Commented Jul 10 at 18:00

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