Legend horizontal orientation doesn't work when extracting icon handles
Ältere Kommentare anzeigen
Hi! I'm using Matlab 2015b and am trying to make a nice plot with a horizontal legend at the bottom. When I do like below, I get nice results (see figure below).
legendHandle = legend('1st' '2nd' '3rd' '4th' '5th' '6th');
legendHandle.Units = 'centimeters';
legendHandle.Orientation = 'horizontal';
legendHandle.Location = 'southOutside';

However, I want to reduce the legend sample line length, so I take out the handle to the icon objects as well.
[legendHandle,icons,~,~] = legend('1st' '2nd' '3rd' '4th' '5th' '6th');
legendHandle.Units = 'centimeters';
legendHandle.Orientation = 'horizontal';
legendHandle.Location = 'southOutside';
lineSamples = findall(icons,'Type','Line')
for i=1:numel(allSamples)
try
lineSamples(i).XData = [lineSamples(i).XData(1) lineSamples(i).XData(2)*0.5];
end
end
This yields a messed up result however (figure below), where the legends are not horizontal but still vertical but squished together.

Can anyone point me in the right direction how to fix this? Thank you! /Ida
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
