# Enlarge the output picture and coordinate axis together like Matlab

Is there anyway to enlarge the output picture and coordinate axis together like Matlab? Like MatrixPlot or other Plot function.

In matlab, there is a zoom button in the picture display window. You can zoom in or out by clicking the Zoom button. The coordinates of the picture will also change accordingly. But I don't know how to do it in mathematica. Or does Mathematica can do this?

like use coordinate matrix x,y to plot a image mesh(x,y,abs(G)).

The button in matlab:

Update:

Matlab can do like this: zoom in/out

We can see in Matlab, the coordinates correspond to the values of the elements of the matrix when the matrix is drawn. But in Mathematica, it's not so easy to graph matrices in terms of coordinates and zoom in.

Matlab code for A simple example:

N=500;
L=100;
I=zeros(N,N);
[x,y]=meshgrid(linspace(-200,200,N));
[x0,y0]=meshgrid(linspace(-0.5,0.5,N));
lamda_1=632;
lamda=lamda_1/1e6;
k=2*pi/lamda;
z=1000000;
h=exp(1j*k*z)*exp((1j*k*(x.^2+y.^2))/(2*z))/(1j*lamda*z);
B=fftshift(fft2(I.*exp((1j.*k.*(x0.^2+y0.^2)))));%
G=h.*B;
figure
mesh(x,y,abs(G));
colorbar
title('Intensity')

• Please be more specific. Commented Apr 20, 2021 at 3:57
• @xzczd Thanks for your reminding, I have updated my question Commented Apr 20, 2021 at 4:46
• Hmm, do you specifically want a GUI button to do this? Or do you simply want to change the plot coordinate ranges (which can be done by modifying the evaluated expression)? Commented Apr 20, 2021 at 4:48
• @thorimur Because sometimes I want to roughly judge the size range of a figure in the picture, it will not be easy to judge if the coordinates can not be enlarged together, So maybe what I want is a GUI button to do the enlarged job with the coordinates together. Commented Apr 20, 2021 at 4:54
• One way to do it might be to enclose everything in a Manipulate that lets you adjust the coordinate ranges! (unfortunately I'm not in a position to write it down at the moment, but it should be fairly straightforward) Commented Apr 20, 2021 at 4:56

Mathematica supports zoom. After you plot, put the mouse on the plot, then click on CTRL and as you slide the mouse up and down, it zooms in and out. Need to hold the CTRL key at same time.

It is also possible to adjust the plot range using Manipulate if you do not want to do the above option.

Using Manipulate, here is a prototype

Manipulate[
Plot3D[Sin[x+y^2],{x,-zoom,zoom},{y,-zoom,zoom},
PlotRange -> {Automatic, Automatic, {-zoom, zoom}},

{{zoom,1,"zoom"},.1,3,.1,Appearance->"Labeled"},

TrackedSymbols:>{zoom}
]


Adjust as needed. In the above, the zoom slider changes all plot ranges on all the axes by same amount.

Well, I really wish Mathematica could add more image viewing capabilities

You could use InteractiveGraphics for more options.

But it seems to support 2D graphics only and not 3D. But if what you want is 2D support, the above have many features.

• Thank you for your answer. Although it is not the best result I wanted, it is a way to solve the problem. By the way the link in the article suggested that the interface I visited did not exist. Commented Apr 20, 2021 at 6:19
• @shrocat corrected the link to Wolfram doc page on zoom. I know it is the exactly the same as Matlab's due to different technologies used by both systems. Commented Apr 20, 2021 at 6:24
• Well, I really wish Mathematica could add more image viewing capabilities. Commented Apr 20, 2021 at 6:31
• ResourceFunction["ManipulatePlot"] and ResourceFunction["DragZoomPlot"] are also related, but they're only for 2D plots, too. Commented Apr 20, 2021 at 10:40

As mentioned in the comment and answer, Manipulate is the standard tool for the task in Mathematica. If you don't bother to code with Manipulate again and again, just define a function:

zoom[plot_] :=
Manipulate[With[{range = PlotRange@Cases[plot, _Graphics | _Graphics3D, {0, ∞}][[1]]},
Show[plot, PlotRange -> scale range]], {{scale, 1}, 0.1, 2}, ControlPlacement -> Top]


Usuage:

zoom@Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}, PlotLegends -> Automatic]


zoom@RevolutionPlot3D[BesselJ[0, r], {r, 0, 20}, PlotRange -> All,
BoxRatios -> {1, 1, 1}, ColorFunction -> "BlueGreenYellow", Mesh -> None,
PlotPoints -> 100]


zoom@MatrixPlot[
Re@Fourier[Table[
UnitStep[i, 4 - i] UnitStep[j, 7 - j], {i, -50, 50}, {j, -50,
50}]]] /. (FrameTicks -> _) -> FrameTicks -> Automatic


• In fact, what I want is a magnification of anywhere like matlab, you can click on any location with the mouse to get a zoom within that location range. If I want to zoom a location range with Manipulate, my idea is to add a and b in the variable range : Plot3D[Sin[x + y^2], {x, -zoom + a, zoom + a}, {y, -zoom + b, zoom + b}], Change a and b to zoom in on a location range. Commented Apr 20, 2021 at 13:47
• @shrocat I'm sorry but I don't have access to matlab and don't quite understand what functionality you're refering to. Can you elaborate a bit with e.g. a GIF or something? As to GIF creation, you may want to try: cockos.com/licecap Commented Apr 20, 2021 at 13:59
• I'm sorry for the late reply. Since I have been very busy recently, I just had time to update my question. I've uploaded a GIF on how Matlab can zoom in on MatricesImage. Commented Apr 26, 2021 at 5:19