필터 지우기
필터 지우기

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

조회 수: 11 (최근 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 Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by