Matab does not currently offer a second x axis.
You can create two duplicate axes and place the x-ticks of the bottom axis on top. Then, scale the second set of x-values to align with the ticks of the first set of x-values.
Here's a demo. The order of many of these steps is important. See footnotes for other important details.
fig = figure();
ax0 = axes();
ax0.Position(3:4) = ax0.Position(3:4) * .95;
ax = copyobj(ax0, fig);
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X) + cos(Y);
co = contourf(ax,X,Y,Z,10);
ax.XTick = -6:2:6;
ax.XLim = ax.XLim;
xlabel(ax, 'Wavelength [nm]')
linkaxes([ax0,ax],'y')
linkprop([ax,ax0], {'position','xScale','units',...
'box','boxstyle','DataAspectRatio','FontName',...
'FontSize','xlim','xtick'});
ax0.XAxisLocation = 'top';
ax0.YTick = [];
x2Limits = [1, 3.5];
x2LimScaled = (x2Limits-x2Limits(1))*range(ax.XLim) + ax.XLim(1);
X1TickNorm = (ax.XTick - ax.XLim(1)) / range(ax.XLim);
X2Tick = (X1TickNorm * range(x2LimScaled)) + x2LimScaled(1);
assert(isequal(numel(X2Tick),numel(ax.XTick)), 'Tick lenghts between the two x axes are not equal.')
set(ax0, 'XTickLabel', compose('%.1f',X2Tick))
xlabel(ax0, 'Energy [eV]')
Footnotes
[1] Reduce the size of the axes to make room for the upper x-axis label added at the end.
[2] The axes will look ugly for now but will be fixed later.
[3] It's important to set all axis properties before linking the axes.
[4] If any properties are added or removed to linkprop(), test it thoroughly.
[5] You'll need to compute these values. They are the x-axis limits of your second contour plot.
[6] compose('%.1f, __) sets tick labels to 1 decimal place. Adjust as needed.
Best Answer