# Multiple X-Axes with separate scales and xlabels

조회 수: 159(최근 30일)
Nathaniel H Werner 2020년 4월 9일
답변: Rajani Mishra 2020년 4월 14일
Hello,
I am trying to make a figure with two x-axes, and I want each axis to have a separate scale because they represent different intervals/variables.
Here is what I have so far.
ax1 = gca; % current axes
ax1.XColor = 'k';
ax1.YColor = 'k';
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none');
ax2.XColor = 'r';
xlim(ax1,[0,AR(q,i)])
set(ax1,'XTick',[0,(0.2:0.9)*3])
The default scale for the top (red) axis is 0 1. I can change the tick marks that are shown but I want them to vertically line up with the black tick marks and for this graph go from -1 to 0. I'm just using 0.1 and 0.2 since they seem to line up by eyeballing it.
set(ax2,'XTick',[0.1,0.2])
set(ax2,'YTick',[])
xlabel(ax1,'Ro(r)')
I also want the there to be an xlabel, but the default location is above the axis since it's on top. How can I move the label so that it's on the same level as tick labels? The only way that I can actually see the label is if I make the figure full screen.
xlabel(ax2,'\omega_r(r)/|min(\omega_r(r))|')
ylabel(ax1,'(y-y_{wing})/\Delta y')
Regular size, you can barely see any of the top xlabel (the arrow is about where I want it to be), but you can see it in fullscreen.
Update: I just figured out I can change the VerticalAlignment to top and this moves the xlabel on top to exactly where I want it. No need to provide an answer for that.  댓글을 달려면 로그인하십시오.

### 채택된 답변

Rajani Mishra 2020년 4월 14일
Hope this helps!

댓글을 달려면 로그인하십시오.

R2018b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!