Issues with legend on a plot?
古いコメントを表示
So I'm having issues correctly displaying a legend for my figure.
I have an image I'm displaying with ground truths marked in red and text labeled 1-11. Then, I'm wanting to have a legend that displays 1 through 11 vertically with the type of ground truth to the right of it. Unfortunately, I'm getting far, far from this. I would post a screenshot, but I'm technically not allowed to which makes troubleshooting a bit cumbersome.
h1=figure(1);imagesc(abs(image));set(gca,'YDir','normal');
hold on
plot(gnd_TruthY_test,gnd_TruthX_test,'r*');
text(gnd_TruthY_test,gnd_TruthX_test,num2str(c'),'Color', [0.859375000000000,0.859375000000000,0.859375000000000],'VerticalAlignment','bottom', ...
'HorizontalAlignment','right')
legend(gt{1,5}(c))
where gt{1,5} contains strings for the ground truth types and c are the indexes that corrspond to the groundtruths in the displayed image.
When I run the above code, my image displays properly but my legend only displays the first ground truth. If I repeatedly click run then the legend eventually builds up. I'm not sure I understand the legend() use in MATLAB >.<
6 件のコメント
dpb
2014 年 4 月 23 日
What's the dimension of gnd_TruthY_test? Do you have 11 line handles in the figure for the legend text to correlate with? The "builds up w/ RUN" makes me think not at the time of the call perhaps.
You can save the line handles from plot and use them as the optional first argument in legend to associate strings with given handle(s).
José-Luis
2014 年 4 月 23 日
Look at the output of gt{1,5}, it might not be what you imagine.
Darren
2014 年 4 月 23 日
Yes, he is...a
whos
and perhaps echoing it could help.
If it is a properly-formed array of 11 strings, legend surely should match 'em up w/ the handles of the lines, so one begins to presume there's something not quite up to snuff therein...
ADDENDUM:
Oh, just a thought--
To check if it's something to do w/ it being in (apparently?) a GUI, try
legend(num2str([1:11]','Line %d'))
in place and see if it doesn't work ok.
BTW, NB: what happens if write the above as
legend(num2str([1:11],'Line %d'))
wherein it's a row vector instead of column...
Darren
2014 年 4 月 23 日
Image Analyst
2014 年 4 月 23 日
Don't call your image variable "image" because that is the name of a built-in function.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Ground Truth Labeling についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!