5
$\begingroup$

Is there any way to make Mathematica to show the legend labels like a real number rather than in fraction form? I read the BarLegend options, however they are just related to graphics so I just set the PlotLegend to Automatic.

A sample of legend I have problem with is shown below:

MatrixPlot[Rm1,
 ColorFunction -> ColorData["GrayTones"],
 ImageSize -> 200,
 PlotLegends -> Automatic]

enter image description here

$\endgroup$
1
  • $\begingroup$ Can you please accept answers to the questions that you've asked so far, if they've actually been helpful (you can accept only one per question)? Accepting it indicates to other users that a particular answer was indeed helpful to you and also rewards the answerer with +15, as a token of appreciation for having helped write an accepted answer. $\endgroup$
    – rm -rf
    Apr 7, 2013 at 1:41

2 Answers 2

2
$\begingroup$

This should do it:

plot = MatrixPlot[Rm1, ColorFunction -> ColorData["GrayTones"],
   ImageSize -> 200, PlotLegends -> Automatic];
MapAt[N, plot, 2]

enter image description here

$\endgroup$
1
  • $\begingroup$ ha ha! simple and effective! Thanks Brett. $\endgroup$
    – K-1
    Apr 6, 2013 at 9:09
2
$\begingroup$

You can also do this way:

plot = MatrixPlot[RandomReal[{0, 1}, {10, 10}], 
  ColorFunction -> ColorData["GrayTones"], ImageSize -> 200, 
  PlotLegends -> Automatic];
plot /. Rational[x_, y_] :> ScientificForm[N[x/y]]

enter image description here

Or combine it with Brett's answer so that it works both for large and small numbers:

plot = MatrixPlot[100000000 RandomReal[{0, 1}, {10, 10}], 
   ColorFunction -> ColorData["GrayTones"], ImageSize -> 200, 
   PlotLegends -> Automatic];
MapAt[N, plot /. Rational[x_, y_] :> ScientificForm[N[x/y]], 2]

enter image description here

plot = MatrixPlot[0.00000001 RandomReal[{0, 1}, {10, 10}], 
   ColorFunction -> ColorData["GrayTones"], ImageSize -> 200, 
   PlotLegends -> Automatic];

MapAt[N, plot /. Rational[x_, y_] :> ScientificForm[N[x/y]], 2]

enter image description here

$\endgroup$

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.