There are multiple axes created by plotyy and hold operates on only one at a time (and, disappointingly, won't accept a vector of multiple handles). Then, on top of that, when you use plotyy a second time you end up creating yet a third axis...
After executing your plotting calls--
>> [hA; hB]
ans =
173.0382 175.0382
173.0382 180.0382
>>
Note the LH axes was plotted into with the second call but a second RH axis was created. So, now you've got three to try to synchronize if you do that. So, "don't DO that!!!" :)
Instead,
>> [hA,h1,h2] = plotyy(x,y1,x,y2);
>> set(hA,'nextplot','add')
>> h3 = plot(hA(1),x,y3);
>> h4 = plot(hA(2),x,y4);
>> legend([h1,h2,h3,h4],'a','b','c','d','location','northoutside','orientation','horizontal')
>>
Now axes will be in synch and both reduced to place the legend as desired.
Best Answer