- https://www.mathworks.com/matlabcentral/answers/91661-is-it-possible-to-plot-the-data-and-show-two-different-scales-for-the-same-data-using-matlab-7-9-r2
- https://www.mathworks.com/matlabcentral/answers/98907-how-can-i-add-a-second-y-axis-with-a-different-scale-in-a-plot-in-matlab-7-9-r2009b
Multiple X-Axes with separate scales and xlabels
29 ビュー (過去 30 日間)
古いコメントを表示
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283211/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/283212/image.png)
0 件のコメント
採用された回答
Rajani Mishra
2020 年 4 月 14 日
I have found few answers similar to your question, Please find their link below:
Hope this helps!
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!