gca while using subplots and sgtitle
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
i want to add arrows to the x and y axis of the subplots. This also works:
p = get(gca, 'Position');
anno = annotation('arrow');
anno.HeadStyle = 'plain';
set(anno, 'X', [p(1) p(1)], 'Y', [p(2) p(2)+p(4)]);
anno = annotation('arrow');
anno.HeadStyle = 'plain';
set(anno, 'X', [p(1) p(1)+p(3)], 'Y', [p(2) p(2)]);
If I give the subplots a title with "sgtitle", however, it no longer works and the arrow representation of the x-axis shifts.I would be very grateful for tips on solving the problem.

Many thanks, Manuel
0 Kommentare
Antworten (1)
Cris LaPierre
am 9 Jan. 2021
Bearbeitet: Cris LaPierre
am 10 Jan. 2021
It appears to actually be the combination of the plot title and the sgtitle. If you just have one or the other, it works fine. My recommendation would be to add the sgtitle first, then the subplots. This way, when you add the annotation, the axes are in their new position.
I did notice that I had to include a drawnow to force the update before getting the axes position.
figure()
sgtitle('Scenario 1: Test Title')
for c = 1:3
subplot(1,3,c)
scatter(randi(5,[1,5])-3,randi(9,[1,5])-5)
axis([-2 2 -4 4])
xlabel('x-axis')
ylabel('y-axis')
title("P_" + num2str(c))
drawnow
p = get(gca, 'Position');
anno = annotation('arrow');
anno.HeadStyle = 'plain';
set(anno, 'X', [p(1) p(1)], 'Y', [p(2) p(2)+p(4)]);
anno2 = annotation('arrow');
anno2.HeadStyle = 'plain';
set(anno2, 'X', [p(1) p(1)+p(3)], 'Y', [p(2) p(2)]);
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Vector Fields 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!