5

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

Brett Champion
  • 20,779
  • 2
  • 64
  • 121
K-1
  • 581
  • 1
  • 3
  • 12
  • 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. – rm -rf Apr 07 '13 at 01:41

2 Answers2

2

This should do it:

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

enter image description here

Brett Champion
  • 20,779
  • 2
  • 64
  • 121
2

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

xslittlegrass
  • 27,549
  • 9
  • 97
  • 186