MATLAB Answers

0

MATLAB sgtitle overlapping with the title of the subplots

Asked by Preetham Manjunatha on 20 Nov 2019 at 7:59
Latest activity Commented on by Jan Kappen about 12 hours ago
When I use the subplots with group title (sgtitle), the title of subplots on top are overlapping with the group title. Does anyone have any suggestions to fix this issue? Any help is much appreciated. Sorry the code is quite messy as it is doing few heavy things!
clear; close all; clc;
load matlab.mat
fig = figure('Position', get(0, 'Screensize'));
% Super title for the movies
sgt = sgtitle(strcat('Stresses',' | Amplification Factor:',{' '},num2str(AmplificationFactor)));
for isig = isig_itr % Stress Component to Plot
for sloc = sloc_itr % Shell Thickness Location to Plot
if (showallstresses_index(1) == 1)
% Subplot axes
ax(sp_cnt) = subplot(row_subplot, col_subplot, sp_cnt);
else
ax(1) = subplot(1, 1, 1);
end
MinStress = +inf;
MaxStress = -inf;
hold on
for iPD=1:2
if (IncludeUndeform ==1 || iPD==2)
if (IncludeUndeform ==1 && iPD==2)
alpha(0.35); % Plot the undeformed shape transparent
end
for iel = 1:nel
% EXTRACT ELEMENT GEOMETRY IN GLOBAL COORDINATE SYSTEM.
for iloc = 1:nnod
x(iloc,1) = coord(lotogo(iel,iloc),1);
y(iloc,1) = coord(lotogo(iel,iloc),2);
z(iloc,1) = coord(lotogo(iel,iloc),3);
end
% FIND LOCAL TO GLOBAL TRANSFORMATION MATRIX, LAMBDA [3x3].
t=Thickness*ones(nnod,1);
[V1,V2,V3,V1T,V2T,V3T]=CreateNormV(x,y,z,t);
% EXTRACT ELEMENT NODAL DISPLACEMENTS IN GLOBAL COORDINATE SYSTEM.
for iloc = 1:nnod
inod = lotogo(iel,iloc);
for idir = 1:nDOFPN
disp(iloc,idir) = 0;
ieqnm = jj(inod,idir);
if (ieqnm ~= 0)
disp(iloc,idir) = disp(iloc,idir) + d(ieqnm);
end
end
for idir = 1:nDOFPN
dispV((iloc-1)*nDOFPN + idir,1) = 0;
ieqnm = jj(inod,idir);
if (ieqnm ~= 0)
dispV((iloc-1)*nDOFPN + idir,1) = d(ieqnm);
end
end
end
% COMPUTE ELEMENT NODAL DISPLACEMENTS IN LOCAL COORDINATE SYSTEM.
[akloc,felloc,amloc] = stiff(young,poisson,density,x,y,z,dTemp,coefExp,t);
[akglob,felglob,L] = Loc2GlobTrans(akloc,felloc,V1,V2,V3);
dispVloc = L*dispV;
% AMPLIFICATION OF THE DEFORMATION.
AmpFactor = AmplificationFactor * (iPD-1);
% PLOT THE STRESS OF EACH FACE AT THE PROJECTION OF INTEGRATION
% POINT IN THE FACE OF THE ELEMENT.
for iface = 1:1
faceNode = faceN(iface,:);
% COMPUTE THE STRESS AT EACH PROJECTION OF THE INTEGRATION POINT
% IN THE FACE USING 2 GAUSS POINTS (2*2).
[sigPr1,sigVon1] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+1,1),Face_G(8*(iface-1)+1,2),dg(sloc),dTemp,coefExp,t);
[sigPr2,sigVon2] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+2,1),Face_G(8*(iface-1)+2,2),dg(sloc),dTemp,coefExp,t);
[sigPr3,sigVon3] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+3,1),Face_G(8*(iface-1)+3,2),dg(sloc),dTemp,coefExp,t);
[sigPr4,sigVon4] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+4,1),Face_G(8*(iface-1)+4,2),dg(sloc),dTemp,coefExp,t);
[sigPr5,sigVon5] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+5,1),Face_G(8*(iface-1)+5,2),dg(sloc),dTemp,coefExp,t);
[sigPr6,sigVon6] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+6,1),Face_G(8*(iface-1)+6,2),dg(sloc),dTemp,coefExp,t);
[sigPr7,sigVon7] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+7,1),Face_G(8*(iface-1)+7,2),dg(sloc),dTemp,coefExp,t);
[sigPr8,sigVon8] = stress(young,poisson,x,y,z,dispVloc,Face_G(8*(iface-1)+8,1),Face_G(8*(iface-1)+8,2),dg(sloc),dTemp,coefExp,t);
if isig ~= 4 % The Principal Stresses S11 S22 and S33
ColorFaceStress = round([sigPr1(isig,1),sigPr2(isig,1),sigPr3(isig,1),...
sigPr4(isig,1),sigPr5(isig,1),sigPr6(isig,1),...
sigPr7(isig,1),sigPr8(isig,1)]', 6, 'significant');
else
ColorFaceStress = round([sigVon1,sigVon2,sigVon3,sigVon4,sigVon5,...
sigVon6,sigVon7,sigVon8]', 6, 'significant');
end
if (MaxStress < max(ColorFaceStress))
MaxStress = max(ColorFaceStress);
end
if (MinStress > min(ColorFaceStress))
MinStress = min(ColorFaceStress);
end
fill3(x(faceNode,1)+AmpFactor*disp(faceNode,1),z(faceNode,1)+AmpFactor*disp(faceNode,3),...
y(faceNode,1)+AmpFactor*disp(faceNode,2),ColorFaceStress');
end
end
end
end
hold off
grid on;
colormap('jet')
title_Var = {'Principal Stress \sigma_1 @ Bottom Surface','Principal Stress \sigma_1 @ Mid Surface',...
'Principal Stress \sigma_1 @ Top Surface','Principal Stress \sigma_2 @ Bottom Surface',...
'Principal Stress \sigma_2 @ Mid Surface','Principal Stress \sigma_2 @ Top Surface',...
'Principal Stress \sigma_3 @ Bottom Surface','Principal Stress \sigma_3 @ Mid Surface',...
'Principal Stress \sigma_3 @ Top Surface','VonMises Stress \sigma_V @ Bottom Surface',...
'VonMises Stress \sigma_V @ Mid Surface','VonMises Stress \sigma_V @ Top Surface'};
title(title_Var((isig-1)*3+sloc));
if(axis_viewtype_3d == 1)
campos(camposxyz) % camera position
camup(camup_vector); % Camera up vector
else
view(45,30);
end
% subplot counter
sp_cnt = sp_cnt + 1;
xlabel('X');ylabel('Z');zlabel('Y');
daspect([1 1 1])
end
end
Link = linkprop(ax, ...
{'CameraUpVector', 'CameraPosition', 'CameraTarget'});
setappdata(gcf, 'StoreTheLink', Link);
c = colorbar;
set(c, 'Position', [0.95 .11 .01 .8150])
c.Label.String = 'Stress Range';
c.Label.FontSize = 12;
axis tight
saveas(fig, 'static_stress_plot.jpg','jpg');

  1 Comment

Your script does not work:
Unrecognized function or variable 'CreateNormV'.
Error in matlabTest (line 31)
[V1,V2,V3,V1T,V2T,V3T]=CreateNormV(x,y,z,t);

Sign in to comment.

Products


Release

R2019b

1 Answer

Answer by Roshni Garnayak about 18 hours ago

You can change the position of the subplots to make the subplot grid title (defined by ‘sgtitle’) visible. To do this, use the following command:
S = subplot('Position',pos);
To know more about it, refer to the following link:
To further customize the plots, you can refer to the following link:https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html

  0 Comments

Sign in to comment.