1

I'm trying to plot a line graph and a bar graph on the same y-axis:

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)]); 

Unfortunately, setting the second y-axis limit like this doesn't affect the second y-axis. Matlab simply does what it thinks is best. However, I need to directly compare the two, so the axes need to be the same. Can anyone help here?

6
  • Don't you miss an output argument to plotyy ? Maybe you forgot to show it in your snippet. eg [ax,BarPlot,RegPlot] = plotyy(...) Commented Jun 16, 2015 at 22:27
  • Maybe you're looking for linkaxes? Commented Jun 16, 2015 at 22:34
  • 1
    @Benoit_11, that turned out to be the problem. Thank you for your help! Commented Jun 17, 2015 at 7:55
  • Great! Do you mind if I write that as an answer so that the thread is closed for future reference? Commented Jun 17, 2015 at 11:59
  • @Benoit_11 no not at all Commented Jun 17, 2015 at 19:47

1 Answer 1

0

In order to use ax(n) you need to provide plotyy with the right output arguments. In your case, you could use the following:

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)]); 
Sign up to request clarification or add additional context in comments.

Comments