How can i add legend to the figure in matlab?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Paul Hoffrichter
le 22 Jan 2021
If you post some code to illustrate the problem, that may be useful to others.
Réponses (1)
Bjorn Gustavsson
le 22 Jan 2021
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 commentaires
Bjorn Gustavsson
le 22 Jan 2021
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
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!