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
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
Answer
To expand on my comment, I think the recent post I wrote for the Mathematica.SE blog will be useful. To summarize:
- Build a custom temperature scale color function using
Blend
and your pooled dataset. - Use
BaseStyle
and related options with a pre-defined set of option value rules to enforce similar styles across the subplot. - Use
Grid
, notGraphicsGrid
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 =
Table[RandomVariate[
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
.
Grid[Partition[
MatrixPlot[#, ColorFunctionScaling -> False,
AspectRatio -> Divide @@ Dimensions[#], ColorFunction -> myblend,
FrameStyle -> AbsoluteThickness[0], PlotRangePadding -> 0,
FrameTicks -> {{ytix, None}, {xtix, None}}] & /@ heatdata, 2]]
Comments
Post a Comment