How set tick location in logarithmic subplot ?
Show older comments
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
1 Comment
...
set(ax2,'XScale','log', ...
'XTick',0:5:35, ...
'XTickLabel',{'0','','10','','20','','30',''}, ...
...
xlim([0 0.1]);
You've tried to set a log-scale axis value to zero -- this can't be good. I'm not positive what handle graphics does with it but since log(0)-->-Inf at best it just ignores it.
Plus, you've set the axis x-limits to the range [0 0.1] after telling it to put the tick marks at 0:5:35 -- thus only one tick is in range of the x-limits. It's not clear to me why you even have any ticks showing.
What you need to do is to set ticks at the desired values within the x-axis limits based on the scale of the data. If you then want those ticks labelled as something other than their actual numeric value, those can be done w/ xticklabel on a 1:1 basis.
Instead of the full-blown code with no data for anybody to try to reproduce and play with, how about just giving a sample (short) data set or two that are giving problem in setting the scale and a description of what scale values you really want. And, what does '0' mean on a log axis???? It belongs way off on the far western horizon in reality...
Accepted Answer
More Answers (0)
Categories
Find more on Subplots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!