Plotting multiple y axes on one side only using addaxis
Show older comments
Hi,
I am using addaxis to plot multiple y axes (first pic), but is there a way to have them all appear on one side (say the right hand side). Is there a better function to do this than addaxis?

If I do this:
figure
plot(x1,y1);
addaxis(x2,y2);
set(gca,'yaxislocation','right');
I get the axes on top of each other.

Thanks
Accepted Answer
More Answers (1)
Tommy
on 1 May 2020
It looks like that function flips back and forth between adding the new axes to the left and adding them to the right. How about calling the function three times and deleting the second set of axes after the third has been added?
plot(1:10, rand(10,1));
addaxis(NaN,NaN);
addaxis(1:10, rand(10,1));
axh = getaddaxisdata(gca,'axisdata');
delete(axh{1})
4 Comments
Dirk
on 1 May 2020
Tommy
on 1 May 2020
Happy to help!
Try this:
plot(NaN,NaN);
set(gca, 'YColor', 'none');
addaxis(1:10, rand(10,1));
addaxis(NaN,NaN);
addaxis(1:10, rand(10,1));
axh = getaddaxisdata(gca,'axisdata');
delete(axh{2})
Dirk
on 4 May 2020
Tommy
on 4 May 2020
You're welcome. I completely agree with Adam's advice.
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
