Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: MatrixPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116110] Re: MatrixPlot
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 2 Feb 2011 06:09:40 -0500 (EST)

Here's your data:

a = {{0.738845, 0.22137, 9.78827*10^-15, 2.12079*10^-15, 0.737321,
     0.219989, 0.742876,
     0.223154}, {-2.24914, -0.0745649, -2.37177*10^-14, \
-6.7765*10^-16, -2.25451, -0.0747736, -2.19921, -0.073661}, \
{-0.0114922, 0.0000990732, 0.163308, 0.00172577, -0.0178998,
     0.000154866, 0.0103928, -0.0000904063}, {0.0000218094,
     0.0000220938, -0.0172577, -0.0147395, 0.0000161738,
     0.0000173347, -0.0000199196, -0.0000201801}, {-0.0176907,
     0.0000917183, -1.54228*10^-13, 1.22102*10^-14, -0.0177778,
     0.000241097, 0.0159182, -0.0000835312}, {0.000423462,
     0.000422684, -3.53884*10^-14, -2.25883*10^-16, -0.000337457, \
-0.000335353, -0.000387491, -0.000385035}, {-2.61035, -0.0780074, \
-2.23373*10^-14, 2.37177*10^-15, 0.737336, 0.217692, 0.743321,
     0.224937}, {0.942536, 0.262962, -2.62276*10^-14,
     4.47751*10^-14, -0.950577, -0.0734003, -5.11481, -0.074505}, \
{0.932657, 0.263023, -2.0706*10^-14,
     2.84864*10^-15, -0.984564, -0.0734043, -4.79912, -0.0745105}, \
{-2.62432, -0.0893055, 4.26041*10^-13, 2.17099*10^-15, 0.734871,
     0.0844196, 0.744577, 0.381002}, {-2.61892, -0.0782246,
     3.25272*10^-13, 1.76942*10^-15, 0.737548, 0.215627, 0.744095,
     0.226961}, {0.957214,
     0.264049, -2.30903*10^-14, -2.83811*10^-12, -1.8876, -0.0733976, \
-5.6553, -0.0746019}, {-2.61892, -0.0782246, -2.27138*10^-14,
     2.72315*10^-15, -2.62452, -0.0784372, 0.744095,
     0.226961}, {0.773361, 0.264356, -1.04948*10^-12, 2.32158*10^-15,
     0.770408,
     0.2664, -2.1883, -0.0746292}, {-7866.78, -32.1848, -38.4366,
     0.856633, 1.11111, -1112.44, 1.11111, 145.613}};
Dimensions@a

{15, 8}

(a - Min@a)/(Max@a - Min@a)

{{0.981919, 0.981854, 0.981827, 0.981827, 0.981919, 0.981854,
   0.981919, 0.981854}, {0.981546, 0.981817, 0.981827, 0.981827,
   0.981545, 0.981817, 0.981552, 0.981817}, {0.981825, 0.981827,
   0.981847, 0.981827, 0.981824, 0.981827, 0.981828,
   0.981827}, {0.981827, 0.981827, 0.981824, 0.981825, 0.981827,
   0.981827, 0.981827, 0.981827}, {0.981824, 0.981827, 0.981827,
   0.981827, 0.981824, 0.981827, 0.981829, 0.981827}, {0.981827,
   0.981827, 0.981827, 0.981827, 0.981826, 0.981826, 0.981826,
   0.981826}, {0.981501, 0.981817, 0.981827, 0.981827, 0.981919,
   0.981854, 0.981919, 0.981855}, {0.981944, 0.981859, 0.981827,
   0.981827, 0.981708, 0.981817, 0.981188, 0.981817}, {0.981943,
   0.981859, 0.981827, 0.981827, 0.981704, 0.981817, 0.981228,
   0.981817}, {0.981499, 0.981815, 0.981827, 0.981827, 0.981918,
   0.981837, 0.981919, 0.981874}, {0.9815, 0.981817, 0.981827,
   0.981827, 0.981919, 0.981853, 0.981919, 0.981855}, {0.981946,
   0.981859, 0.981827, 0.981827, 0.981591, 0.981817, 0.981121,
   0.981817}, {0.9815, 0.981817, 0.981827, 0.981827, 0.981499,
   0.981817, 0.981919, 0.981855}, {0.981923, 0.98186, 0.981827,
   0.981827, 0.981923, 0.98186, 0.981553, 0.981817}, {0., 0.97781,
   0.977029, 0.981933, 0.981965, 0.842987, 0.981965, 1.}}

Ntice all the values are virtually identical, except for the highest and  
lowest. That's why your ColorFunction didn't do a great job.

Looking at it with ListPlot, you can see the problem:

ListPlot[Sort@Flatten@a, PlotRange -> All]

There are some distinct values between, but they're only noticeable if you  
exclude the highs and lows:

ListPlot[Sort@Flatten@a]

Here are some things that work fairly well:

MatrixPlot[a, ColorFunctionScaling -> True, ColorFunction -> Hue]]

gradient = RandomChoice@ColorData["Gradients"]
MatrixPlot[a, ColorFunctionScaling -> True, ColorFunction -> gradient]

MatrixPlot[a, ColorFunctionScaling -> True,
  ColorFunction -> ColorData["TemperatureMap"]]

The second one chooses different colors each time you evaluate it, and the  
choices are

ColorData["Gradients"]

{"AlpineColors", "Aquamarine", "ArmyColors", "AtlanticColors", \
"AuroraColors", "AvocadoColors", "BeachColors", "BlueGreenYellow", \
"BrassTones", "BrightBands", "BrownCyanTones", "CandyColors", \
"CherryTones", "CMYKColors", "CoffeeTones", "DarkBands", \
"DarkRainbow", "DarkTerrain", "DeepSeaColors", "FallColors", \
"FruitPunchColors", "FuchsiaTones", "GrayTones", "GrayYellowTones", \
"GreenBrownTerrain", "GreenPinkTones", "IslandColors", "LakeColors", \
"LightTemperatureMap", "LightTerrain", "MintColors", "NeonColors", \
"Pastel", "PearlColors", "PigeonTones", "PlumColors", "Rainbow", \
"RedBlueTones", "RedGreenSplit", "RoseColors", "RustTones", \
"SandyTerrain", "SiennaTones", "SolarColors", "SouthwestColors", \
"StarryNightColors", "SunsetColors", "TemperatureMap", \
"ThermometerColors", "ValentineTones", "WatermelonColors"}

ColorFunctionScaling -> True apparently does a better job than your manual  
scaling.

To distinguish values by force, you can try this:

b = (Partition[Ordering@Flatten@a, 8] - 1)/(-1 +
      Times @@ Dimensions@a);

ListPlot[Sort@Flatten@b, PlotRange -> All]

MatrixPlot[b, ColorFunctionScaling -> True, ColorFunction -> Hue]

gradient = RandomChoice@ColorData["Gradients"]
MatrixPlot[b, ColorFunctionScaling -> True, ColorFunction -> gradient]

MatrixPlot[b, ColorFunctionScaling -> True,
  ColorFunction -> ColorData["TemperatureMap"]]

There are, of course, other color functions and scaling methods you can  
try, such as

c = Rescale[a, {Min@a, Max@a}, {380, 750}];
colors = ColorData["VisibleSpectrum"]
MatrixPlot[c, ColorFunctionScaling -> False, ColorFunction -> colors]

Bobby

On Tue, 01 Feb 2011 05:52:42 -0600, Sofia Figueiredo <sofiafig at gmail.com>  
wrote:

> None of the options worked...
> My command is:
>  MatrixPlot[a,
>   ColorFunction -> (GrayLevel[(# - Min[a])/(Max[a] - Min[a])] &),
>   ColorFunctionScaling -> False, PlotRange -> All]
> And generates a matrix of whites. The matrix ranges between -7866.78
> and 145, so some color should be visible.
> Am I doing something wrong in this command?
> Thanks in advance!
> Sofia
>
> On Sat, Jan 29, 2011 at 7:01 AM, DrMajorBob <btreat1 at austin.rr.com>  
> wrote:
>> There is PlotRange -> All, and we recently discovered PlotRange -> Full.
>>
>> Maybe one of those will work.
>>
>> Bobby
>>
>> On Fri, 28 Jan 2011 05:16:40 -0600, Sofia Figueiredo  
>> <sofiafig at gmail.com>
>> wrote:
>>
>>> Dear Math group,
>>> I have a 14x8 matrix "A" and I want to present it as a color map. I am
>>> trying to use the command MatrixPlot, but I do not manage to set the
>>> upper and lower limit. I tried to define the
>>> PlotRange->{Min[A],Max[A]}, but it did not work.
>>> How can I set the upper limite of the color range to the maximal value
>>> of my matrix and the lower limite of the color range to the minimal
>>> value of my matrix?
>>> I also find strange that, in the MatrixPlot I get, the system can
>>> diferentiate between the values 0.7 and 0.2, but then attributes the
>>> same color to values as disparate as 1 and 145. How can I avoid this?
>>>
>>> Thanks in advance.
>>> Sofia
>>>
>>
>>
>> --
>> DrMajorBob at yahoo.com
>>
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: statistical comparison of parameters from two applications of NonlinearModelFit
  • Next by Date: Re: statistical comparison of parameters from two applications of NonlinearModelFit
  • Previous by thread: Re: MatrixPlot
  • Next by thread: Re: Repeatable ways to crash the MathKernel