Multiple X-Axes with separate scales and xlabels
92 views (last 30 days)
Nathaniel H Werner on 9 Apr 2020
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,...
ax2.XColor = 'r';
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.
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.
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 on 14 Apr 2020
I have found few answers similar to your question, Please find their link below:
Hope this helps!