Plotyy - two x axes ticks not lining up correctly
Show older comments
Hi there,
I am using the plotyy function to plot two sets of data using 2 y axes and 2 x axes. For some reason the tick marks from the bottom x axis are "bleeding" on to the top x axis as you can see in this picture:
Any reason why this might be happening? Here is the code I'm using:
% Create figure
figure1 = figure('XVisual','','Color',[1 1 1]);
% Create difpercent vector
difpercent = (difinput./basinput).*100;
% plotyy graph
[AX,H1,H2] = plotyy(basinput,bas_hpa,difpercent,dif_hpa,@semilogx,@plot)
set(AX(1),'XColor',[0 0 0],'YColor',[0 0 0],'Parent',figure1,...
'YTickLabel',{'200','400','600','800',''},...
'YTick',[200 400 600 800 1000],...
'YMinorTick','on',...
'YDir','reverse',...
'XMinorTick','off',...
'XTickMode','auto',...
'Position',[0.13 0.112403846153846 0.710158478605388 0.793461538461539],...
'FontSize',16,...
'FontName','Times');
axis auto;
set(H1,'Color',[0 0 0],'linewidth',2)
legend([,units,],'%','Location','Best')
% Create ylabel
ylabel('Pressure (hPa)','FontWeight','bold','FontSize',18,...
'FontName','Times');
% Create xlabel
xlabel([,xaxistitle,],'FontWeight','bold','FontSize',18,...
'FontName','Times');
% set properties for axis 2
set(AX(2),'XAxisLocation','top',...
'YAxisLocation','right',...
'YTick',[200 400 600 800 1000],...
'YTickLabel',{'11.8','7.18','4.20','1.95',''},...
'YMinorTick','on',...
'XMinorTick','off',...
'XTickMode','auto',...
'YDir','reverse',...
'FontSize',16,...
'FontName','Times',...
'Position',[0.13 0.112403846153846 0.710158478605388 0.793461538461539],...
'Color','none',...
'XColor','k','YColor','k');
% set Xlabel and Ylabel for axes 2
set(get(AX(2),'Ylabel'),'String','Altitude (km)','FontWeight','bold',...
'FontSize',18,...
'FontName','Times');
set(get(AX(2),'Xlabel'),'String',[,x2axistitle,],'FontWeight','bold',...
'FontSize',18,...
'FontName','Times');
% set H2 plot line properties
set(H2,'Color',[0 0 0],'linewidth',2,'linestyle',':')
% Set output size
set(gcf, 'units', 'pixels');
set(gcf, 'position', [200 150 650 550]);
THANK YOU!!!
Aaron
3 Comments
Walter Roberson
on 9 Oct 2011
Is there a difference between this and your still-active http://www.mathworks.com/matlabcentral/answers/17079-two-y-axes-not-lining-up-semilogx-for-one-line-for-the-other ?
Aaron Burdick
on 9 Oct 2011
Aaron Burdick
on 14 Oct 2011
Answers (1)
Aaron Burdick
on 13 Oct 2011
0 votes
Categories
Find more on Combine Multiple Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!