how to label second x and y axes
27 views (last 30 days)
Show older comments
Rabih Sokhen
on 31 Mar 2021
Commented: Rabih Sokhen
on 31 Mar 2021
hello guys
in the following code, i don't know how to label the x axis on the top and the y axis that's on the right
anybody have a idea?
thank you
clear all
clc
subplot(2,2,4)
x1 = linspace(0,100,101);
y1 = 2*x1;
x2=3*x1;
y2=4*x1;
plot(x1,y1)
xlabel('x1')
ylabel('y1')
hAx(1)=gca;
hAx(2)=axes('Position',hAx(1).Position,'XAxisLocation','top','xlim',[x2(1) x2(end)],'YAxisLocation','right','ylim',[y2(1) y2(end)],'color','none');
uistack(hAx(2), 'bottom')
0 Comments
Accepted Answer
Cris LaPierre
on 31 Mar 2021
Use the following syntax with hAx(2) as your target.
plot(1:100)
xlabel('x1')
ylabel('y1')
hAx(1)=gca;
hAx(2)=axes('Position',hAx(1).Position,'XAxisLocation','top','xlim',[0 300],'YAxisLocation','right','ylim',[0 400],'color','none');
uistack(hAx(2), 'bottom')
xlabel(hAx(2),'x2')
ylabel(hAx(2),'y2')
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!