How to change symbol size and contour size in legend simultaneously?
83 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wanted to make the marker size of scatter plot larger and the token size of the contour symbol in legend smaller, so I used the following code:
x=1:20;
a=rand(20,20);
figure; hold on
scatter(3,4)
contour(x,x,a)
h=legend('sp','cp');
h.ItemTokenSize = [10,5]; % Make both symbols smaller
To make the marker size of the scatter plot larger, I tried to get icons:
[h,icons]=legend('sp','cp');
h.ItemTokenSize = [10,5]; % Doesn't work anymore
icons = findobj(icons,'Type','patch');
icons = findobj(icons,'Marker','none','-xor');
set(icons(1),'MarkerSize',12); % To make scatter plot marker size larger
However, I lose control over the contour token size.
Can anyone please help me with this? Thanks!
0 Kommentare
Antworten (1)
Gouri Chennuru
am 27 Sep. 2020
Hi Jing,
You can open MATLAB 2020a and execute the following code,
x=1:20;
a=rand(20,20);
figure;
hold on
scatter(3,4)
contour(x,x,a)
[h,icons]=legend('sp','cp');
h.ItemTokenSize = [10,5];
icons = findobj(icons,'Type','patch');
icons = findobj(icons,'Marker','none','-xor');
set(icons(1),'MarkerSize',12);
This code works fine in MATLAB 2020a.
If you are still facing the issue, provide additional information so that issue will be resolved.
Hope this Helps!
1 Kommentar
Joscha Weinert
am 5 Dez. 2021
Hello,
I am facing the same issue.
My figure plot is based on an app designer program.
To adjust the length, I can use:
leg.ItemTokenSize = [x1,x2];
If I generate the Legend by
leg = legend(...);
So it works fine.
But I also want to adjust the marker size afterwards.Therefore I need the icons. So i use
[leg, icons] = legend(...);
h = findobj(icons,'type','patch');
set(h,'MarkerSize',1);
So I can adjust the marker size, but I can't change the length of the markers or lines in the legend no more.
Either way, one of my options gets lost.
@Gouri Chennuru: I tried your code and it worked. In another thread was mentioned, that app designer could be the problem. But maybe you have a solution. That would be really great. Maybe there is way to get the icons without this code:
[leg, icons] = legend(...);
Thank you in advance.
Siehe auch
Kategorien
Mehr zu Legend 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!