How can i add legend to the figure in matlab?
3 次查看(过去 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!