# Using MatrixPlot, how can I dynamically zoom in and out with my mouse? [duplicate]

I have a MatrixPlot output which I would like to zoom around in, drawing boxes that define a zoom region with my mouse. These things are all fairly standard in Labview... surely Mathematica must have a similar set of abilities?

For an example matrix, we can write:

TestArray = Array[RandomInteger[{0, 1}] &, {100, 100}];
MatrixPlot[TestArray]

-

## marked as duplicate by Mr.Wizard♦Jul 30 '13 at 5:58

Having your MatrixPlot done, click once on it and pressing a small orange rectangle at the bottom of the plot, drag it to zoom your plot. Use simply RandomInteger[1, {100, 100}] instead of Array[RandomInteger[{0, 1}] &, {100, 100}]. – Artes Jun 29 '13 at 10:05
@Artes Thanks for the tip about not using Array. However, I meant being able to use my mouse to define a window within the graphic, which we then clip and zoom to. Is this possible? – UKa Jun 29 '13 at 10:09
Duplicate of: mathematica.stackexchange.com/q/7142/5 – R. M. Jun 29 '13 at 12:44

Have you explored the capabilites of Manipulate yet?

Manipulate[
MatrixPlot[TestArray,
Mesh -> m,
ColorFunction -> cf,
PlotRange -> {{xmin, xmax}, {ymin, ymax}}],
{xmin, 1, 50, 1}, {ymin, 1, 50, 1},
{xmax, 51, 100, 1}, {ymax, 51, 100, 1},
{m, 1, 50},
]


Here's a slightly more mouse-y one:

coordsToRowColumns[pt_, mag_, w_, h_] :=
Module[{rmin, cmin, rmax, cmax},
rmin =  pt[[1]];
cmin = h - pt[[2]] ;
rmax = pt[[1]] + mag ;
cmax = cmin + mag;
{{cmin, cmax}, {cmin, cmax}}]
TestArray = RandomReal[1, {100, 100}];
Manipulate[
Row[{
MatrixPlot[
TestArray,
ImageSize  -> 200,
ColorFunction -> cf],
MatrixPlot[
TestArray,
ImageSize  -> 400,
PlotRange -> coordsToRowColumns[pt, mag, 100, 100],
AspectRatio -> 1,
ColorFunction -> cf
]
}
],
{{pt, {0, 100}} , Locator},
{{mag, 50, "Magnification"}, 1, 100},

@uka something similar here which could be easily adapted. Look up Locators too, for mouse input. – cormullion Jun 29 '13 at 10:25