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

5 Ansichten (letzte 30 Tage)
Sim am 29 Mai 2023
Beantwortet: Sim am 30 Mai 2023
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?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Walter Roberson am 29 Mai 2023
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 KommentarKeine anzeigenKeine ausblenden
Sim am 30 Mai 2023
Bearbeitet: Sim am 30 Mai 2023
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?

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Sim am 30 Mai 2023
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]);
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by