How can the colors of ones choice be added to the legends manually in an image ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Shivam Pande
il 28 Feb 2018
Risposto: Walter Roberson
il 1 Mar 2018
I wish to add the colors to the legends as per the rgb values of the corresponding color in the image. The image can be displayed using the code written below:
x1=ones(30); x2=2*ones(30); x3=3*ones(30);
x=[x1,x2,x3];
y1=zeros(30,90); y2=zeros(30,90); y3=zeros(30,90); y=zeros(30,90,3);
y1(x==1)=0; y2(x==1)=77; y3(x==1)=26;
y1(x==2)=102; y2(x==2)=255; y3(x==2)=102;
y1(x==3)=204; y2(x==3)=102; y3(x==3)=0;
y(:,:,1)=y1; y(:,:,2)=y2; y(:,:,3)=y3;
imshow(uint8(y))
0 Commenti
Risposta accettata
Walter Roberson
il 1 Mar 2018
You only have one graphics object (the image() object created by imshow), so you can only have one legend entry. The icon for an image is a very small image.
What you should probably do instead is to
lh(1) = line(nan, nan, 'Color', [0, 77, 26]/255);
lh(2) = line(nan, nan, 'Color', [102, 255, 102]/255);
lh(3) = line(nan, nan, 'Color', [204, 102, 0]/255);
legend(lh, {'Case 1', 'Case2', 'Case 3'})
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend 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!