How can I put shapes (as circles, and arrows) and (multi-rows) texts outside a Matlab plot?

7 次查看(过去 30 天)
How can I put shapes (as circles, and arrows) and (multi-rows) texts outside a Matlab plot, as in the following picture?
Indeed, I would like to reproduce (something very similar to) the following picture. Any suggestions? Would it be feasible with Matlab?

采纳的回答

Walter Roberson
Walter Roberson 2023-5-29
The formal method is to use annotation
However note that annotation() cannot use data coordinates, so it can be messy to place items correctly in the case where the area might be resized.
There are some File Exchange contributions to assist with placing annotations in data units.
The more advanced technique is to set the Clipping property of the axes to 'off'; when you do that then anything drawn within the OuterPosition of the axes will show up (normally only things in the InnerPosition show up.) You might need to specifically manipulate InnerPosition as much smaller than typical relative to OuterPosition and you might need to change the PositionConstraint property (which I believe had a different name in the past.)
  1 个评论
Sim
Sim 2023-5-30
编辑:Sim 2023-5-30
Thanks a lot @Walter Roberson! by following your indications, I found a suitable example in How can I plot objects outside of an axes using Line or annotation objects in MATLAB?, from which I tried to make some modifications to it, trying to get closer to what I would need:
% This is the original figure
figure
hAxes = subplot(1,2,1);
axis(hAxes, [0 1 0 1]); % Freeze axis limits
hold on
hLine = line([0.5 2], [0.5 0.5], 'Color', 'k', ...
'Marker', 'o', ...
'Clipping', 'off');
hRect = rectangle(hAxes, 'Position', [1.5 0.1 1 0.25], ...
'Curvature', [0.2 0.2], ...
'FaceColor', 'r', ...
'Clipping', 'off');
hold off
axis equal
% Then, I changed the following:
% (1) I increased axis limits
% (2) I changed the arguments of my subplot (from subplot(1,2,1), to subplot(3,3,5))
% Indeed, I used subplot(3,3,5) since I would like to place several objects,
% as shapes, arrows and texts, all around my figure.
% (3) I added a second shape on the left side of the plot
% (4) I changed both position and and cruvature of the first rectangle (now a circle)
figure
hAxes = subplot(3,3,5);
axis(hAxes, [0 2 0 2]); % Freeze axis limits
hLine = line([0.5 2], [0.5 0.5], 'Color', 'k', ...
'Marker', 'o', ...
'Clipping', 'off');
hRect = rectangle(hAxes, 'Position', [1.5 0.1 0.25 0.25], ...
'Curvature', [1 1], ...
'FaceColor', 'r', ...
'Clipping', 'off');
hRect = rectangle(hAxes, 'Position', [-2 0.8 0.85 0.85], ...
'Curvature', [1 1], ...
'FaceColor', 'b', ...
'Clipping', 'off');
axis equal
However, it looks like that the tick labels of my plot change and they do not stay still from 0 to 2. For example, in this figure just here above, the x-axis goes from -1 to 1. How to fix definitely the axis limits?
If this minimum example works, I can accept your Answer!

请先登录,再进行评论。

更多回答(1 个)

Sim
Sim 2023-5-30
I found a minimum working example:
ax = subplot(3,3,5);
hold on
scatter(0:3,0:3,[],'filled','Clipping', 'off')
plot(0:3,0:3,'Clipping', 'off')
line([3 4], [0.5 0.5], 'Color', 'k', ...
'Marker', 'o', ...
'Clipping', 'off');
rectangle('Position', [-2 3 0.25 0.25], ...
'Curvature', [1 1], ...
'FaceColor', 'r', ...
'Clipping', 'off');
rectangle('Position', [-2 0.8 0.85 0.85], ...
'Curvature', [1 1], ...
'FaceColor', 'b', ...
'Clipping', 'off');
hold off
axis equal
axis(ax, [0 2 0 2]);

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by