Matlab - 在同一 y 轴上绘制条形图和折线图
Matlab - plot bar and line graph on the same y axis
我正在尝试在同一 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 只是做它认为最好的事情。但是,我需要直接比较两者,所以轴需要相同。有人可以帮忙吗?
为了使用 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)]);
我正在尝试在同一 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 只是做它认为最好的事情。但是,我需要直接比较两者,所以轴需要相同。有人可以帮忙吗?
为了使用 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)]);