4
$\begingroup$

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: enter image description here


Update:

Matlab can do like this: zoom in/out

enter image description here

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') 
$\endgroup$
10
  • 4
    $\begingroup$ Please be more specific. $\endgroup$ – xzczd Apr 20 at 3:57
  • $\begingroup$ @xzczd Thanks for your reminding, I have updated my question $\endgroup$ – shrocat Apr 20 at 4:46
  • $\begingroup$ 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)? $\endgroup$ – thorimur Apr 20 at 4:48
  • $\begingroup$ @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. $\endgroup$ – shrocat Apr 20 at 4:54
  • 1
    $\begingroup$ 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) $\endgroup$ – thorimur Apr 20 at 4:56
7
$\begingroup$

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.

See RotateZoomAndPanGraphics

enter image description here

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}},
ImagePadding->30,PerformanceGoal->"Quality"],

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

TrackedSymbols:>{zoom}
]

enter image description here

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

edit Reply to comment:

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

You could use InteractiveGraphics for more options.

enter image description here

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

enter image description here

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ – shrocat Apr 20 at 6:19
  • $\begingroup$ @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. $\endgroup$ – Nasser Apr 20 at 6:24
  • 1
    $\begingroup$ Well, I really wish Mathematica could add more image viewing capabilities. $\endgroup$ – shrocat Apr 20 at 6:31
  • 3
    $\begingroup$ ResourceFunction["ManipulatePlot"] and ResourceFunction["DragZoomPlot"] are also related, but they're only for 2D plots, too. $\endgroup$ – xzczd Apr 20 at 10:40
5
$\begingroup$

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]

enter image description here

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

enter image description here

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

enter image description here

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ – shrocat Apr 20 at 13:47
  • $\begingroup$ @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 $\endgroup$ – xzczd Apr 20 at 13:59
  • $\begingroup$ 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. $\endgroup$ – shrocat Apr 26 at 5:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.