MATLAB Answers

Multiple X-Axes with separate scales and xlabels

17 views (last 30 days)
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.
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.


Sign in to comment.

More Answers (0)




Translated by