How can i add legend to the figure in matlab?
1 回表示 (過去 30 日間)
古いコメントを表示
I have plotted a figure with 9 plots in it and in legend i have given 9 names to display. All good upto now.
But after some editing on the actual figure like in terms of axis setting and figure settings, i could find that 2 out of 9 of legend information is missing in the legend box on the figure, i tried setproperty and going to string but not getting what to do after that. It is asking to enter expressions. so what should i enter to get my legend information back ?
2 件のコメント
Paul Hoffrichter
2021 年 1 月 22 日
If you post some code to illustrate the problem, that may be useful to others.
回答 (1 件)
Bjorn Gustavsson
2021 年 1 月 22 日
It is often preferable to add the legend after the other adjustments. I often find that legends and colorbars doesn't perfectly adjust to changes in axes size and position, and the only solution I've found is to add them last. Maybe that is enough to fix your problem.
HTH
3 件のコメント
Bjorn Gustavsson
2021 年 1 月 22 日
This works perfectly fine in matlab2020a:
OP = exp(randn(9,numel(j)));
ph = semilogy(j,OP);
clf
for i1 = 1:size(OP,1),
ph(i1) = semilogy(j,OP(i1,:));
hold on
end
set(ph(1:3),'color','b')
set(ph(4:6),'color','g')
set(ph(7:9),'color','r')
set(ph(1:3:end),'Marker','*')
set(ph(2:3:end),'Marker','o')
set(ph(3:3:end),'Marker','d')
xlabel('Es/No')
ylabel('OP');
title('OP Vs Avg SNR with r0=2 bits/sec/hz');
legend(ph,...
'simulated with N = 1 for \eta = 0.15',...
'simulated with N= 2 \eta = 0.15',...
'simulated with N = 5 \eta = 0.15',...
'simulated with N = 1 for \eta = 0.45',...
'simulated with N= 2 \eta = 0.45',...
'simulated with N = 5 \eta = 0.45',...
'simulated with N = 1 for \eta = 0.85',...
'simulated with N= 2 \eta = 0.85',...
'simulated with N = 5 \eta = 0.85');
If you've removed some parts of the legend by interactively editing the figure, then I don't know what's possible. In that case I figure it is far less fuss to simply replot the figure?
HTH
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!