how to plot a gragh with 2 x axes (top and bottom) with different lables and single left y axis

조회 수: 2 (최근 30일)
Step_size = [5 10 15 20 25 30 35 40]; % bottom x axis
FMC_models = [7650000 3830000 2550000 1920000 1530000 1280000 1100000 960000];
RIA_models = [3689 1853 1232 935 747 624 545 463];
PMA_models = [26 26 26 26 26 26 26 26];
PSA_models = [10000 10000 10000 10000 10000 10000 10000 10000];
%% need to use semilog y axis
Initial_trial_force = [0 500 1000 1500 2000 2500 3000 3500]; % top x axis
FMC_models_1 = [960000 840000 710000 600000 460000 340000 210000 90000];
RIA_models_1 = [463 442 398 350 297 244 171 66];

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 22일
편집: Ameer Hamza 2020년 4월 22일
Try this
Step_size = [5 10 15 20 25 30 35 40]; % bottom x axis
FMC_models = [7650000 3830000 2550000 1920000 1530000 1280000 1100000 960000];
RIA_models = [3689 1853 1232 935 747 624 545 463];
PMA_models = [26 26 26 26 26 26 26 26];
PSA_models = [10000 10000 10000 10000 10000 10000 10000 10000];
%% need to use semilog y axis
Initial_trial_force = [0 500 1000 1500 2000 2500 3000 3500]; % top x axis
FMC_models_1 = [960000 840000 710000 600000 460000 340000 210000 90000];
RIA_models_1 = [463 442 398 350 297 244 171 66];
labels1 = {'FMC models', 'RIA models', 'PMA models', 'PSA models'};
labels2 = {'FMC models 1', 'RIA models 1'};
figure();
ax_bottom = axes();
ax_bottom.YScale = 'log';
hold(ax_bottom);
plot(ax_bottom, Step_size, FMC_models, ...
Step_size, RIA_models, ...
Step_size, PMA_models, ...
Step_size, PSA_models);
legend(ax_bottom, labels1, 'Location', 'northeast');
ax_top = axes();
ax_top.XAxisLocation = 'top';
ax_top.YAxis.Visible = 'off';
ax_top.Color = 'none';
ax_top.YScale = 'log';
ax_top.YLim = ax_bottom.YLim;
hold(ax_top);
plot(ax_top, Initial_trial_force, FMC_models_1, ...
Initial_trial_force, RIA_models_1, 'LineStyle', '--');
legend(ax_top, labels2, 'Location', 'northwest', 'Color', 'none');
  댓글 수: 6

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by