Two x-axis for the same y-axis

조회 수: 63 (최근 30일)
Zihad Azad
Zihad Azad 2020년 2월 20일
댓글: Zihad Azad 2020년 2월 20일
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.
  댓글 수: 1
Zihad Azad
Zihad Azad 2020년 2월 20일
Thanks, I got it now

댓글을 달려면 로그인하십시오.

추가 답변 (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