Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a matrix of data that I am plotting via ArrayPlot.

FData = {{0., 0., 0.066812, 0., 0., 0., 0.}, {0., 0.479787, 0., 
   0.0683112, 0., 0., 0.}, {0.0669646, 0., 0.0697005, 0., 0., 0., 
   0.}, {0., 0.0683715, 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0., 
   0.}, {0., 0., 0., 0., 0., 0., 0.}, {0., 0., 0., 0., 0., 0., 0.}}

I would like to reverse the color bar colors in the Plot legend. I used:

ArrayPlot[
 FData,
 PlotLegends -> 
  BarLegend[{GrayLevel, {0, Max[FData]}}, 
   LabelStyle -> {FontSize -> 20}], DataReversed -> False]

And this gives me:

The colors are flipped in this figure and I'd like the darkest to represent the highest number in my matrix.

When I try to "Reverse" my data (which doesn't seem sound to me) using the below snippet:

FData[[1 ;; 7, 1 ;; 7]]
ArrayPlot[
 FData[[1 ;; 7, 1 ;; 7]],
 PlotLegends -> 
  BarLegend[{GrayLevel, {0, Reverse[FData[[1 ;; 7, 1 ;; 7]]]}}, 
   LabelStyle -> {FontSize -> 20}], DataReversed -> False]

And that gives me nothing!

Edit/Errata

I have been using PlotLegends -> BarLegend[{GrayLevel, {0, 1}}, LabelStyle -> {FontSize -> 20}] to set the font size. Based on the answers below, how can I go about changing the font size?

I know this is very basic but I can't quite figure out whats going on!

share|improve this question
    
What Mma version are you using? –  belisarius May 13 '13 at 18:31
    
@belisarius Mathematica 9.0... Will make the edit –  drN May 13 '13 at 18:33
add comment

2 Answers

up vote 4 down vote accepted
With[{g = GrayLevel[1 - #] &},
       ArrayPlot[FData, ColorFunction -> g, PlotLegends -> BarLegend[{g, {Min@FData, Max@FData}}, 
                 LabelStyle -> Directive[Blue, Large]]]]

enter image description here

share|improve this answer
    
How do I change the font size of the text in the colorbar? I was using BarLegend for that purpose... ArrayPlot[mat, PlotLegends -> BarLegend[{GrayLevel, {0, 1}}, LabelStyle -> {FontSize -> 20}]] –  drN May 13 '13 at 18:49
    
@drN See edit, please –  belisarius May 13 '13 at 19:06
    
Thank you. I would have never thought of this. –  drN May 13 '13 at 19:08
    
You might want to change rData to FData.. Thank you though, the essense of the answer still exists. –  drN May 13 '13 at 19:09
    
@drN yeah, I changed your FData for rData in my notebook. Always try to start your symbols with lowercase! –  belisarius May 13 '13 at 19:12
add comment

With ColorFunctionScaling -> True (default), the data values are rescaled to between 0 and 1, which is then input to the ColorFunction. So the general solution to "reverse" the color scheme is to simply input 1 - x, where x is the rescaled data point, as shown in belisarius' answer.

If you're using a built-in color scheme, you can use the "Reverse" property to automatically reverse the colors as in the following example:

With[{data = RandomReal[1, {10, 10}]},
    {ArrayPlot[data, ColorFunction -> "Temperature", PlotLabel -> "Original"], 
     ArrayPlot[data, ColorFunction -> ColorData[{"Temperature", "Reverse"}], 
        PlotLabel -> "Reversed"]
    } // GraphicsRow
]

enter image description here


The documentation for the *Legend functions fully specify how to use the options to style them. Here's an example:

ArrayPlot[RandomReal[1,{10, 10}], ColorFunction -> ColorData[{"Temperature", "Reverse"}], 
    PlotLegends -> BarLegend[{ColorData[{"Temperature", "Reverse"}], {0, 1}}, 
        LabelStyle -> Directive[FontFamily -> "Palatino", FontSize -> 14, Red], 
        LegendLabel -> "Colorbar", LegendFunction -> "Panel"
    ]
]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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