필터 지우기
필터 지우기

Plot formatting: including zoomed in regions

조회 수: 1 (최근 30일)
HC98
HC98 2023년 5월 15일
답변: Yash 2023년 5월 22일
So I know how to create a separate set of axes on the plot using
% create smaller axes in top right, and plot on it
axes('Position', [.32 .22 .25 .15])
box on
plot(x, data, 'k')
% box off
But what I'd like to do is add an arrow to the magnified plot which points to the area if that makes sense?

답변 (1개)

Yash
Yash 2023년 5월 22일
Hi @HC98,
To add an arrow pointing to a specific area on the magnified plot, you can use the annotation function in MATLAB. Here's an example of how you can accomplish this:
% Create the main plot
figure;
plot(x, y, 'k');
hold on;
% Create smaller axes for the magnified plot
axes('Position', [.32 .22 .25 .15])
box on
plot(x, y, 'k')
% Define the coordinates for the arrow
arrowX = [arrowStartX, arrowEndX]; % Replace with actual x-coordinates
arrowY = [arrowStartY, arrowEndY]; % Replace with actual y-coordinates
% Plot the arrow using the 'annotation' function
annotation('arrow', arrowX, arrowY);
% Customize the appearance of the arrow (optional)
arrow = gca;
arrow.Color = 'red'; % Set arrow color
arrow.LineWidth = 1.5; % Set arrow line width
% Add any additional formatting or annotations as needed
hold off;
In this code snippet, arrowStartX and arrowStartY represent the starting coordinates of the arrow, while arrowEndX and arrowEndY represent the ending coordinates. Replace these values with the actual coordinates of the area you want to point to in the magnified plot.
The annotation function is used to create the arrow, and you can customize its appearance by modifying properties such as color and line width. You can also add other formatting or annotations to the magnified plot as needed.
Feel free to adjust the position and size of the smaller axes to fit your desired layout. You can modify the values in the axes('Position', [.32 .22 .25 .15]) line to adjust the position and size of the magnified plot within the figure.
Remember to replace x and y with the actual data you want to plot in both the main plot and the magnified plot.
I hope this helps!

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by