Plot formatting: including zoomed in regions
4 ビュー (過去 30 日間)
古いコメントを表示
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
2023 年 5 月 22 日
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!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!