Clear Filters
Clear Filters

Adding a second x-axis to the top

79 views (last 30 days)
Zihad Azad
Zihad Azad on 17 Feb 2020
Commented: Ahmed Hassebo on 22 Sep 2020
Hello dear altruist,
in need of help here. I need to add a second x-axis to the top of my graph here:
The x-axis values at the top is just 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
%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]);

Answers (1)

Ajay Kumar
Ajay Kumar on 17 Feb 2020
  2 Comments
Zihad Azad
Zihad Azad on 17 Feb 2020
Thanks. But using this I have run into another problem. Basically, I am using this to plot a curve of zeros:
How do I get rid of the line plot in the middle?
The code:
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);
line(l*1e7,y,'Parent',ax2,'Color','k','linewidth',2);
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]);
Ahmed Hassebo
Ahmed Hassebo on 22 Sep 2020
Remove this line from the second code
% line(l*1e7,y,'Parent',ax2,'Color','k','linewidth',2);

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!