【问题标题】:Matlab - plot bar and line graph on the same y axisMatlab - 在同一y轴上绘制条形图和折线图
【发布时间】:2015-09-01 22:14:05
【问题描述】:

我正在尝试在同一 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 只是做它认为最好的事情。但是,我需要直接比较两者,所以轴需要相同。有人可以帮忙吗?

【问题讨论】:

  • 您不会错过plotyy 的输出参数吗?也许你忘了在你的 sn-p 中显示它。例如[ax,BarPlot,RegPlot] = plotyy(...)
  • 也许您正在寻找linkaxes
  • @Benoit_11,原来是这个问题。感谢您的帮助!
  • 太棒了!你介意我把它写成答案,以便关闭线程以供将来参考吗?
  • @Benoit_11 一点也不

标签: matlab plot line


【解决方案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)]);

【讨论】:

    猜你喜欢
    • 2020-05-06
    • 2016-10-09
    • 2018-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多