フィルターのクリア

Why legend something wrong

1 回表示 (過去 30 日間)
Michael Wang
Michael Wang 2020 年 5 月 30 日
回答済み: Alan Stevens 2020 年 5 月 30 日
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;

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 30 日
編集済み: Ameer Hamza 2020 年 5 月 30 日
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;

その他の回答 (1 件)

Alan Stevens
Alan Stevens 2020 年 5 月 30 日
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.

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by