How can the colors of ones choice be added to the legends manually in an image ?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Walter Roberson
2018년 3월 1일
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!