Clear Filters
Clear Filters

How to zoomin the figure with data & background?

3 views (last 30 days)
Hi! I have one question regarding the zoomin of Matlab figure. Here is my code just in case:
x = 1:500;
y = sind(x);
plot(x,y,'linewidth',3)
axis tight;
hold on
I = imread('peppers.png');
h = image(xlim,-ylim,I);
uistack(h,'bottom')
If you run the above code, the below figure is the output.
I want to zoomin some specific areas of this figure with data and background simultaneously. I've tried several times; however, only data (blue line) was zoom-in, but the background doesn't... I want to know how to zoomin the data and the background at the same time. Do you guys have some solution regarding my problem? I need your help!!
  1 Comment
DGM
DGM on 15 Jun 2022
What version/environment are you using? Also, what method are you using to zoom in on the figure?

Sign in to comment.

Answers (1)

Shubham
Shubham on 4 Sep 2023
You can zoom in programmatically by setting the desired range and zooming in using xlim and ylim.
For example:
x = 1:500;
y = sind(x);
plot(x,y,'linewidth',3)
axis tight;
hold on
I = imread('peppers.png');
h = image(xlim,-ylim,I);
uistack(h,'bottom')
% Set the desired zoomed-in range
x_zoom = [250, 300];
y_zoom = [-1, -0.8];
% Zoom in on the plot
xlim(x_zoom)
ylim(y_zoom)
The above code produces the following output:
In the above image, the plot is zoomed in along with the background image. Similarly, you can zoom in and out by setting the limits to zoom in on your desired points.
Hope this helps!!

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!