Two x-axis for the same y-axis

55 次查看(过去 30 天)
Hello dear altruist,
in need of help here. I need to add a second x-axis to the top of my graph here:
I tried from my end and this is the result. The x-axis on top is just normalized scale from 0 to 1 in reverse. Basically, the x-axis values at the top needs to be the inverse of the variable below (2*pi/kx). This would help me visualize the data both in terms of wavevector and wavelength. The codes and files are attached herwith. Thanks in advance.
clc; clear all;
load infinite;
% transpose matrix is not required
A1= log10(fs1);
kx=ky;
h1=figure
p1=pcolor(kx*1e-6,f/1e12,A1);
xlabel('\it{k_x} (\rm{\times10^6 m^{-1}})');ylabel('{\itf} (THz)');
ylim([33 1600]);
set(h1, 'Units', 'normalized');
get(h1, 'Position');
set(h1,'Position',[ 0.12 0.22 0.18 0.33]);
%colormap setting needs to come after each subplot
shading interp;
colormap jet(500);%colormap need to be set to jet for Blue-yellow-red map
ax1 = gca; % current axes
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,'XAxisLocation','top','YAxisLocation','right','Color','none','YTick',[],'TickLength',[.00014 .0014]);
xlabel(ax2,'\rm lambda(\mum)');
l=(2*pi)/ky;
% L=length(l);
% y=zeros(L);
hold(ax2,'on');
% plot(ax2,l*1e7,y);
% line(l*1e7,y,'Parent',ax2,'Color','k');
set(ax2,'XDir','reverse');
% set(gcf,'visible','off');
%font properties
FS='Fontsize';
fs1=20;
fs2=20;
FN='Fontname';
fn='Times New Roman';
set(findall(gcf,'type','axes'),FS,fs1,FN,fn);
set(findall(gcf,'type','text'),FS,fs2,FN,fn);
x0=100;
y0=100;
width=700;
height=500;
set(gcf,'units','pixels','position',[x0,y0,width,height]);

采纳的回答

Jakob B. Nielsen
Jakob B. Nielsen 2020-2-20
编辑:Jakob B. Nielsen 2020-2-20
You're on the right track with some of the stuff you have tabbed out. All you need is to set the x and y limits for your ax2 axes.
set(ax2,'XDir','reverse');
ylim(ax2,[33 1600]); %set the y and x limits on ax2
xlim(ax2,[0 100])
From here, you can just change the ax2 x axis limits to be whatever you want them to be, and use the regular commands for the ticks etc.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by