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.

Is there an easy approach - hopefully built-in - to partitioning MatrixPlot graphics into rows or columns (or both) of graphics sharing the same underlying options?

For example, in the following graphic, the red rectangles indicate where partitions should occur, and the respective sub-Rasters (along with FrameTicks etc) can then be reorganized using Row

enter image description here

This particular graph (excluding the rectangles which were generated in Epilog) has Length 6, of which all but the first Part are related to options. But it's tedious to even list what parts of the partitions component correspond to which parts, which subsequently must be modified - for example FrameTicks are to be repositioned (reindexed).

Obviously, because the "heatmap" color scale is shared among all the members of the desired partition, it's not feasible to partition the matrix prior and then mapping through MatrixPlot

share|improve this question
Please explain "sharing the same underlying options". –  David Carraher Oct 6 '12 at 1:09
For example, the ColorData, the FrameLabels.. any option passed to the original MatrixPlot –  alancalvitti Oct 6 '12 at 1:11
I'd suggest setting up a custom Blend function based on the pooling of your data, and then building a Grid of the subplots. See my recent post on the Mathematica.SE blog –  Verbeia Oct 6 '12 at 1:35

1 Answer 1

up vote 4 down vote accepted

To expand on my comment, I think the recent post I wrote for the Mathematica.SE blog will be useful. To summarize:

  1. Build a custom temperature scale color function using Blend and your pooled dataset.
  2. Use BaseStyle and related options with a pre-defined set of option value rules to enforce similar styles across the subplot.
  3. Use Grid, not GraphicsGrid to combine plots with different widths.

Here is an example, using the same tick labels as in the blog post. First, here's some data, specified as a 3D list. Notice how I've used the general iteration capabilities of Table to create a list of two 5 by 10 matrices and two 3 by 10 matrices.

heatdata = 
    LogNormalDistribution[0, 2], {i, 10}], {i, {5, 5, 3, 3}}];

Next we define the custom Blend to scale across the whole data set. Note that Min and Max work for the whole data set even though it's a nested list, but you need to Flatten the data before applying Mean.

myblend = 
 Evaluate@Blend[{{Min[heatdata], Blue}, {Mean[Flatten@heatdata], 
      White}, {Max[heatdata], Orange}}, #] &

(* Blend[{{0.00629577, RGBColor[0, 0, 1]}, {6.37397, 
    GrayLevel[1]}, {215.341, RGBColor[1, 0.5, 0]}}, #1] & *)

You can now Map the MatrixPlot function to each matrix in the data set. Notice that I'm also using a pure function to determine the approprate AspectRatio so it all fits together nicely. Then it's just a matter of partitioning the plots the way you want and applying Grid.

  MatrixPlot[#, ColorFunctionScaling -> False, 
     AspectRatio -> Divide @@ Dimensions[#], ColorFunction -> myblend,
      FrameStyle -> AbsoluteThickness[0], PlotRangePadding -> 0, 
     FrameTicks -> {{ytix, None}, {xtix, None}}] & /@ heatdata, 2]]

enter image description here

share|improve this answer
(1) In my situation, the TickMarks will not be the same across plots, since they are partitioned from the original TickMarks. (2) is it possible to selectively suppress some TickMarks for some (but not all) of the partitioned plots? For example, only show F1...Fn along the y-axis of only the leftmost pair of plots (and similarly for E1...Em along the x-axis for only the bottom plots)? –  alancalvitti Oct 6 '12 at 19:30

Your Answer


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.