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

8 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 29 Mag 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 Commento
Sim
Sim il 30 Mag 2023
Modificato: Sim il 30 Mag 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?
If this minimum example works, I can accept your Answer!

Accedi per commentare.

Più risposte (1)

Sim
Sim il 30 Mag 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]);

Categorie

Scopri di più su Graphics Object Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by