![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326375/image.png)
Avoid lower case in legend by plotting legend with 'DisplayName'
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have again a similar Problem, but in this case I can't separate legend, and : 'Interpreter','none' is here also not working. How can I print names like 001_M1_Distance_0.5m_AKG_C1000S_F1_MS1 without undercases?
label1 = extractBefore({i(j).name}, ".mat");
label1 = extractAfter(label1, "_");
...........
if any(M1)
plot(M1(:,2),M1(:,1),'-o','DisplayName',label1{1});
hold on
end
if any(M2)
plot(M2(:,2),M2(:,1),'-o','DisplayName',label2{1});
hold on
end
if any(M3)
plot(M3(:,2),M3(:,1),'-o','DisplayName',label3{1});
hold on
end
if any(M4)
plot(M4(:,2),M4(:,1),'-o','DisplayName',label4{1});
hold on
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326360/image.png)
Thanks!
0 commentaires
Réponse acceptée
Image Analyst
le 3 Juil 2020
Use the 'Interpreter', 'none' option in legend():
% Read headers
plot(1:10);
hold on
plot(4:14);
legend('plot_1', 'plot_2', 'Interpreter', 'none', 'Location', 'Northwest');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/326375/image.png)
6 commentaires
Image Analyst
le 4 Juil 2020
I'd use counter instead of cnt - it's more descriptive it sounds a lot less naughty, than "I know, one cnt is enough".
You might want to consider contains(string, pattern, 'IgnoreCase', true) instead of strcmp(). Or at least use strcmpi() for more robustness. And you might want to cast to lower because you're never totally sure if the extension returned by the operating system will be upper case or lower case:
extractBefore(lower({i(j).name}), '.mat');
When you're assigning the M's you don't need parentheses:
M4 = R4 / cnt4;
Personally I like spaces around operators but that's a matter of style.
You should also have an else clause with no if. What if none of the criteria are satisfied? Will your code will work, or will you get an error downstream because nothing got assigned?
Plus de réponses (1)
madhan ravi
le 3 Juil 2020
Use labels without _ .
regexprep('001_M1_Distance_0.5m_AKG_C1000S_F1_MS1','_','') % to remove underscores
Voir également
Catégories
En savoir plus sur Graphics Object Programming 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!