首页 文章

Matlab - 在同一y轴上绘制条形图和折线图

提问于
浏览
1

我试图在同一个y轴上绘制折线图和条形图:

figure; 
plotyy(Pert, Rfootvel(:,i+1), Pert, 0,'bar','plot');
hold(ax(1), 'on');
legend('Pert 1-8', 'Base');
ylim(ax(2), [0 1]);
title(['The avg pert velocity of the first step vs the avg base velocity, PP' num2str(j)]);

不幸的是,像这样设置第二个y轴限制不会影响第二个y轴 . Matlab只是做了它认为最好的事情 . 但是,我需要直接比较两者,因此轴需要相同 . 有人可以帮忙吗?

1 回答

  • 1

    要使用 ax(n) ,您需要为plotyy提供正确的输出参数 . 在您的情况下,您可以使用以下内容:

    figure; 
    
    %// Here BarPlot and RegPlot are not really needed so you could replace them with ~.
    
    [ax,BarPlot,RegPlot] = plotyy(Pert, Rfootvel(:,i+1), Pert, 0,'bar','plot');
    
    hold(ax(1), 'on');
    
    legend('Pert 1-8', 'Base');
    ylim(ax(2), [0 1]);
    title(['The avg pert velocity of the first step vs the avg base velocity, PP' num2str(j)]);
    

相关问题