MATLAB: How set tick location in logarithmic subplot

logarithmic plotMATLABticks location

Hi,
I work on oceanographic data to display the speed current and the salinity along the depth. I make a subplot in which each plot correspond to a specific hour of tide. But the problem is the tick location in logarithmic axis which change for each plot (see the plot).
I want the same scale for the salinity axis and in each plot. To make this, i have try to change the data aspect ratio but nothing change. I hope someone will try to help me. Please find my code below:
fig_02 = figure;
set(gcf,'color','white','PaperType','A4','paperorientation','landscape');
S1 = subplot(2,5,1);
% ====== 1st variable ======




L1 = line(AQD.speed(202:219),AQD.pressure(202:219),'LineStyle','none','Marker','.','color',color(4,:));
ax1 = gca;
set(ax1,'XColor',color(4,:),'YColor','k','Ydir','reverse','YTicklabel',{'0';'';'2';'';'4';'';'6';'';'8'});
xlim([0 1.5]); ylim([0 8]);
% legend(L1,'Vit. courant','Location','NorthWestOutside');
% ====== 2nd variable ======




ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k','Ygrid','on');
set(ax2,'XScale','log','XTick',0:5:35,'XTickLabel',{'0','','10','','20','','30',''},'Ydir','reverse','YTicklabel','');
xlim([0 0.1]); ylim([0 8]);
L2 = line(PF_4(1:9,5),PF_4(1:9,2),'LineStyle','-.','Marker','*','MarkerSize',6,'Color','k','Parent',ax2);
% legend(L2,'Salinité','Location','SouthWestOutside');
%..........................................................................



subplot(2,5,2)
% ====== 1st variable ======
L3 = line(AQD.speed(690:701),AQD.pressure(690:701),'LineStyle','none','Marker','.','color',color(4,:));
ax1 = gca;
set(ax1,'XColor',color(4,:),'YColor','k','Ydir','reverse','YTicklabel',{'0';'';'2';'';'4';'';'6';'';'8'});
xlim([0 1.5]); ylim([0 8]);
% ====== 2nd variable ======
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k','Ygrid','on');
set(ax2,'XScale','log','XTick',0:5:35,'XTickLabel',{'0','','10','','20','','30',''},'Ydir','reverse','YTicklabel','');
xlim([0 0.1]); ylim([0 8]);
L4 = line(PF_7(1:9,5),PF_7(1:9,2),'LineStyle','-.','Marker','*','MarkerSize',6,'Color','k','Parent',ax2);
%..........................................................................
subplot(2,5,3)
% ====== 1st variable ======
L5 = line(AQD.speed(1749:1772),AQD.pressure(1749:1772),'LineStyle','none','Marker','.','color',color(4,:));
ax1 = gca;
set(ax1,'XColor',color(4,:),'YColor','k','Ydir','reverse','YTicklabel',{'0';'';'2';'';'4';'';'6';'';'8'});
xlim([0 1.5]); ylim([0 8]);
% ====== 2nd variable ======
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k','Ygrid','on');
set(ax2,'XScale','log','XTick',0:5:35,'XTickLabel',{'0','','10','','20','','30',''},'Ydir','reverse','YTicklabel','');
xlim([0 0.1]); ylim([0 8]);
L6 = line(PF_13(1:9,5),PF_13(1:9,2),'LineStyle','-.','Marker','*','MarkerSize',6,'Color','k','Parent',ax2);
%..........................................................................
subplot(2,5,4)
% ====== 1st variable ======
L7 = line(AQD.speed(2895:2919),AQD.pressure(2895:2919),'LineStyle','none','Marker','.','color',color(4,:));
ax1 = gca;
set(ax1,'XColor',color(4,:),'YColor','k','Ydir','reverse','YTicklabel',{'0';'';'2';'';'4';'';'6';'';'8'});
xlim([0 1.5]); ylim([0 8]);
% ====== 2nd variable ======
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k','Ygrid','on');
set(ax2,'XScale','log','XTick',0:5:35,'XTickLabel',{'0','','10','','20','','30',''},'Ydir','reverse','YTicklabel','');
xlim([0 0.1]); ylim([0 8]);
L8 = line(PF_19(1:9,5),PF_19(1:9,2),'LineStyle','-.','Marker','*','MarkerSize',6,'Color','k','Parent',ax2);
%..........................................................................
subplot(2,5,5)
% ====== 1st variable ======
L9 = line(AQD.speed(3750:3768),AQD.pressure(3750:3768),'LineStyle','none','Marker','.','color',color(4,:));
ax1 = gca;
set(ax1,'XColor',color(4,:),'YColor','k','Ydir','reverse','YTicklabel',{'0';'';'2';'';'4';'';'6';'';'8'});
xlim([0 1.5]); ylim([0 8]);
% ====== 2nd variable ======
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top','YAxisLocation','right','Color','none','XColor','k','YColor','k','Ygrid','on');
set(ax2,'XScale','log','XTick',0:5:35,'XTickLabel',{'0','','10','','20','','30',''},'Ydir','reverse','YTicklabel','');
xlim([0 0.1]); ylim([0 8]);
L10 = line(PF_25(1:9,5),PF_25(1:9,2),'LineStyle','-.','Marker','*','MarkerSize',6,'Color','k','Parent',ax2);
Best regards,
Sylvain

Best Answer

Why are you plotting salinity on a log scale in the first place? At first I thought perhaps you were trying to get your salinity and current values on the same scale so you wouldn't have to use separate axes for them, but that doesn't seem to be the case; you've got the multiple axes set up properly. I don't think I've ever seen a salinity profile on a log scale (but then, I don't work with freshwater environments, so perhaps it's common there?).
Anyway, you could probably simplify your code with the use of a few loops. Then, as dpb pointed out, you need to set a non-zero lower limit for your axes; I recommend using the minimum of your data:
depth = linspace(0, 8, 20);
adcp = rand(20,5) * 1.5;
salt = 5 + rand(20,5) * 20;
for ii = 1:5
h.ax(ii,1) = subplot(1,5,ii);
h.ax(ii,2) = axes('position', get(h.ax(ii,1), 'position'), ...
'color', 'none', 'xaxisloc', 'top');
h.adcp(ii) = line(adcp(:,ii), depth, 'parent', h.ax(ii,1), ...
'marker', '.', 'color', 'b', 'linestyle', 'none');
h.salt(ii) = line(salt(:,ii), depth, 'parent', h.ax(ii,2), ...
'marker', '.', 'color', 'k', 'linestyle', '-');
end
set(h.ax(:,1), 'xlim', [0 1.5], 'xcolor', 'b');
tk = 5:5:30;
tklbl = strtrim(cellstr(num2str(tk')));
[tklbl{1:2:end}] = deal('');
set(h.ax(:,2), 'xscale', 'log', 'xtick', tk, 'xticklabel', tklbl, ...
'xlim', [min(salt(:)) 35]);