Re-activate Y label exponent

1 次查看(过去 30 天)
Richard Rees
Richard Rees 2020-5-23
Afternoon everyone,
Attached are two figures, before and after the linking of axes of subplots. Annoyingly, the last row exponent is being switch off and the Y labels being reset to 0 when linking the final row together. I can manually reactivate it using the specify axis tick values and labels, but I need to remember what the exponent value was and input the Y labels again. I increased in the number y tick format to 4f prior to this because I think it is decimal point problem between the final subplot but the problem persists. Is there a way to stop this?
Thanks
  2 个评论
dpb
dpb 2020-5-23
Think would need to at least see the code to look at what you've done/are doing...
Which axes are being linked?
Richard Rees
Richard Rees 2020-5-23
Hi, attached is the input file for the subplot code below (it's abit long winded). It all goes wrong at 'linkaxes(ha(16:18),'xy') %dP2' down the bottom. Prior to this everything works fine, I think it maybe because of the decimal place difference between the three subplots in that row.
% Scientific papaer style
set(0,'defaulttextinterpreter','latex')
set(0,'defaultaxesfontname','Times')
set(0,'defaultaxesfontsize', 8)
Ylabel_names = {'$PWP$', '$X dis.$','$Y dis.$','$X strain$','$Y strain$','$dP^{2}/dT^{2}$'};
Ylabel_units = {'$(kPa)$','$(m)$','$(m)$','','','$(m/s^{2})$'};
title_names = {'$Cell\ A$','$Cell\ B$','$Cell\ C$'};
combo_M = load('combo_M.mat');
d_output = 'Boundaries';
plottype = 'Cell_CBA';
intrpl_fctr = 10;
ctrl_cells = 3;
switch(d_output)
case 'Boundaries'
graph_title = sprintf('%s%c slope constraint comparison',out,176);
legend_names = {'$None$', '$XY$', '$X$', '$Y$'};
lgd_tit = '$\underline{Constraint}$';
skip = 0;
otherwise
skip =1;
end
if skip ==0
close
CC =0;
mk_cnt = 0;
xlimit = 430;
fh = figure();
fh.WindowState = 'maximized';
set(gcf,'color','w');
switch plottype
case 'Cell_CBA'
%flip the combo_M array ABC-->CBA and use that order for SP
if CC == 0
combo_CBA = fliplr(combo_M);
CC =1;
end
row = size(combo_M{1},2);
cols = size(combo_M,2) ;
[ha,pos] = tight_subplot(row,cols,[.02 .01],[.06 .095],[.4 .4]);
total_count = row*cols;
lkaxis = reshape(1:total_count,cols,row).'; %Creates row vectors for sp numbers
V = combo_CBA;
count = 1;
count_V = 1;
for aa = 1:total_count
axes(ha(aa));
for kk = 1:size(V{count}{count_V},1)
x = 1:numel(V{count}{count_V}(kk,:));
y = V{count}{count_V}(kk,:);
hold on
plot(x,y)
end
xlim([0 xlimit])
y1 = ylim;
y1_min = y1(1);
y1_max = y1(2);
% Try to round up the Y axis to whole numbers for + & - y axis values
if y1(1)<0
y1_min = y1(1)*1.5;
elseif y1(1) >=0
y1_min = y1(1)*1.5;
elseif y1(2)<=0
y1_max = y1(2)*0.75;
elseif y1(2)>0
y1_max =y1(2)*1.25;
end
ylim = ([y1_min y1_max]);
ytickformat('%.1f')
x1 = xlim;
XT = xticks;
%XT_new = XT(1):intrpl_fctr:round(x1(2),1);
set(gca,'XTick',XT, 'xticklabel',XT/intrpl_fctr)
grid on
axis normal
if aa <= total_count-3
set(gca,'xticklabel',[])
end
if aa ~=lkaxis(:,1)
set(gca,'yticklabel',[])
end
if count <numel(ctrl_cells) %3
count = count+1;
elseif count ==numel(ctrl_cells)
count = 1;
count_V = count_V +1 ;
end
end
%set(gcf,'units','centimeters')%,'position',[10 10 12 6])
sgtitle(graph_title,'fontName','Times','fontweight','normal','fontangle','italic','Interpreter', 'LaTeX');
p1=get(ha(1),'position'); % position of UL-most axes
p3 = get(ha(3),'position');
p2=get(ha(total_count),'position'); % ditto for LR-most
hAxOuter=axes('units','normalized','position',[p1(1) p2(2) p2(1)+p2(3)-p1(1) p1(2)+p1(4)-p2(2)], ...
'color','none','visible','off');
hAxOuter.XLabel.Visible='on';
axes(hAxOuter)
xlabel('$Time\ (min)$','fontName','Times','interpreter','latex')
for ii = 1:cols
title(ha(ii),title_names(ii))
end
%lgd = legendflex(ha(3),legend_names,'fontsize',8,'fontweight','bold','interpreter','latex','xscale',0.45,'buffer',[72.5 -2],'box','off','location','eastoutside');
%title(lgd,lgd_tit,'interpreter','latex','fontweight','bold','fontsize',9)
for kk = 1:row
ylabel(ha(lkaxis(kk,1)),{Ylabel_names{kk},Ylabel_units{kk}},'fontweight','bold')
%linkaxes(ha(lkaxis(kk,1):lkaxis(kk,3)),'xy')
end
linkaxes(ha(1:3),'xy') %PWP
linkaxes(ha(4:9),'xy') % X.Y dis
linkaxes(ha(10:15),'xy') %X.Y strains
linkaxes(ha(16:18),'xy') %dP2
% try and reactivate y label
ax = ancestor(ha(16),'axes');
ax.YAxis.Exponent,'auto';
ax.YAxis.TickLabelFormat = '%.1f';
ax.YAxis.TicklabelsMode,'auto';
otherwise
end
end

请先登录,再进行评论。

回答(0 个)

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by