Why legend something wrong
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Michael Wang
le 30 Mai 2020
Réponse apportée : Alan Stevens
le 30 Mai 2020
I got some sample codes from this
I am not sure why plotting some with wrong legends : (
clear;clc;close all;
h = [0.05 0.025 0.0125 0.00625 0.003125];
A = [0.0103 0.005 0.0019 0.0121 0.1031];
B = [0.0103 0.0052 0.0026 0.0012 0.0011];
C = [0.0103 0.0052 0.0026 0.0013 0.0011];
% Plot filtered data
figure();
%axis([0 3.5e-3 0 1e-3]);
loglog(h, A,'k-'); % plot
hold on;
scatter(h,A,'k','*');
loglog(h, B,'k--');
scatter(h,B,'k','d');
loglog(h, C,'k:');
scatter(h,C,'k','o');
xlabel('grid space [m]')
ylabel('Error Value');
title('Relation of Error Value and Grid Spacing [m]')
legend('A','B','C');
hold off;
grid on;
0 commentaires
Réponse acceptée
Ameer Hamza
le 30 Mai 2020
Modifié(e) : Ameer Hamza
le 30 Mai 2020
No need to call loglog and scatter seperately. loglog() can do both
% clear;clc;close all;
h = [0.05 0.025 0.0125 0.00625 0.003125];
A = [0.0103 0.005 0.0019 0.0121 0.1031];
B = [0.0103 0.0052 0.0026 0.0012 0.0011];
C = [0.0103 0.0052 0.0026 0.0013 0.0011];
% Plot filtered data
figure();
%axis([0 3.5e-3 0 1e-3]);
loglog(h, A,'k-*'); % plot
hold on;
loglog(h, B,'k--d');
loglog(h, C,'k:o');
xlabel('grid space [m]')
ylabel('Error Value');
title('Relation of Error Value and Grid Spacing [m]')
legend('A','B','C');
hold off;
grid on;
0 commentaires
Plus de réponses (1)
Alan Stevens
le 30 Mai 2020
Instead of
loglog(h, A,'k-'); % plot
hold on;
scatter(h,A,'k','*');
% simply use
loglog(h, A, 'k*-');
% with the same for the others (i.e. no need for a separate scatter plot)
% then legend will work ok.
0 commentaires
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!