Magnifying a Segment of Plot in MATLAB PATCH-Figure

38 vues (au cours des 30 derniers jours)
Kovacs Mario
Kovacs Mario le 21 Août 2023
Commenté : Kovacs Mario le 6 Sep 2023
Hi,
I tried to create a magnified part of a PATCH figure but unfortunately, I couldn't find any options for how to make it, like on the image below. I know that there are options for how to magnify a part of a regular plot(x,y) figure, but with PATCH I have no idea.
There is an example below of a PATCH used Figure and I want to magnify some part of this.
Do you have any idea how can I make it?
Thank you so much for your helpful comments!

Réponse acceptée

akshatsood
akshatsood le 31 Août 2023
Hi Kovacs,
I understand that you want to magnify a segment of plot in MATLAB patch figure. I have considered the following patch plot for the rest of the answer whose implementation in MATLAB is as follows. I have annotated the desired region with a red rectangle.
% assuming a sample data for plotting patch
x = [2; 4; 6];
y = [4; 5; 4];
c = [0; 6; 4];
figure
patch(x,y,c) % create a patch plot
% red rectangle indicates the segment to be magnified
rectangle('Position',[3 4.4 1 0.4],'EdgeColor','r','LineWidth',2);
colorbar
Method 1: specifying the axes limits using xlim and ylim to zoom into the desired region
In this method, you tweak the limits of the x and y axis to extract the desired portion from the figure. Additionaly, you can leverage daspect function to control data unit length along each axis. It should be noted that, this method overwrites the original plot in the figure and illustrates only the zoomed segment. Here is the code snippet to implement the method.
zoomedInRegion = ([3 4 4.4 4.8]); % area of interest
% modifying the x and y limits
xlim(zoomedInRegion(1:2));
ylim(zoomedInRegion(3:4));
daspect('auto'); % adjust the aspect ratio of axis if required
Method 2: creating a new axis in the same figure to represent the zoomed segment
In case you wish to wish to observe the original plot as well as the zoomed segment on the same figure, you can create a new axes on the same figure and position it accordingly. Now you can utilise copyobj and findobj functions to recreate the patch plot on the new axis. Further, adjust the x and y limits to zoom into the desired region. Here is the code snippet for your reference
axNew = axes('Position',[.7 .7 .2 .2]); % creating a new axes and positioning it
copyobj(findobj('Type', 'patch'), axNew); % copying the patch plot to new axes
% adjuisting x and y limits to zoom into the suitable area
zoomedInRegion = ([3 4 4.4 4.8]); % area of interest
% modifying the x and y limits for the new axes
axNew.XLim = zoomedInRegion(1:2);
axNew.YLim = zoomedInRegion(3:4);
annotation('textarrow',[.52 .64],[.64 .8]) % adding arrow annotation
Apart from the methods mentioned above, have a look at following tools on File Exchange
I hope this helps.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by