Conflict between "TextLocation" and "annotation" when using "Legend"
Mostrar comentarios más antiguos
Hi, I would like to use the position retrieved with the function TextLocation (by MathWorks Support Team) and use it for the annotation position.
However, when I do so the legend text in the subplot (2,2) takes the text of the annotation. How to solve this thing?
% input
x = -10:10;
city = {'London', 'Paris', 'Berlin','Madrid'};
season = {'summer','winter'};
colors = {'blue','red','black','magenta'};
% my plot (using "subaxis")
figure
for i = 1 : 4
subaxis(2,2,i);
y1 = (rand(1,21)-0.5)*20;
y2 = (rand(1,21)-0.5)*10;
hold on
p1(i) = plot(x, y1, 'Color', colors{i}, 'LineStyle','--');
p2(i) = plot(x, y2, 'Color', colors{i}, 'LineStyle','-');
hold off
p1(i).DisplayName = [city{i} ', ' season{1}];
p2(i).DisplayName = [city{i} ', ' season{2}];
legend % <-- "legend" here to see the legend text in the subplots
end
% annotation
str1 = 'further information';
str2 = sprintf('annotation: %s', str1);
% use the "TextLocation" position for "annotation"
mytext = TextLocation(str2,'Location','southeast');
dim = mytext.Position;
delete(mytext)
annotation('textbox',dim,'String',str2,'FitBoxToText','on');
% again "legend" here below to see the legend text in the subplot (2,2)
% since the legend text disappears in that subplot when using "TextLocation"
legend

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!