How to add one sgtitle per row of suplots
조회 수: 42 (최근 30일)
이전 댓글 표시
Hi,
I want to add a sgtitle per row of subplots, which works well for the first row by using the command sgtitle.
Each subplot already has a title, therefore the title 'Mit Wasserbewegung' of the 2nd row doesnt seem to appear in the figure. Does anybody have a quick and easy solution for this problem?
댓글 수: 0
답변 (2개)
Alan Stevens
2022년 11월 20일
Here's a quick and dirty way:
x = 0:0.01:2*pi;
for i=1:6
y = sin(x+i*pi/4);
subplot(2,3,i)
plot(x,y)
if i == 2
title({'Ohne'; int2str(i)})
elseif i == 5
title({'Mit'; int2str(i)})
else
title({' '; int2str(i)})
end
end
Alan Stevens
2022년 11월 20일
Try
subplot(2,3,1)
scatter(62,VWE3a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
title('DMS 3')
xlim([59.5 64.5])
ylim([-0.2 2])
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
grid on
hold on
scatter(62,VWE3b_diff,50,'MarkerEdgeColor','[0 0.5 1]','Marker','x','linewidth',2)
scatter(62,VWE3c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
scatter(64,WWE3a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
scatter(64,WWE3b_diff,50,'MarkerEdgeColor','[0 0.5 1]','MarkerFaceColor','[0 0.5 1]','Marker','x','LineWidth',2)
scatter(64,WWE3c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
subplot(2,3,2)
scatter(62,VWE4a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
ylim([-0.2 2])
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
title({'Ohne Wasserbewegung','DMS 4'}) %%%%%%%%%%%%%%%%%%%%%%%%
grid on
hold on
scatter(62,VWE4b_diff,50,'MarkerEdgeColor','[0 0.5 1]','Marker','x','linewidth',2)
scatter(62,VWE4c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
scatter(64,WWE4a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
scatter(64,WWE4b_diff,50,'MarkerEdgeColor','[0 0.5 1]','Marker','x','LineWidth',2)
scatter(64,WWE4c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
subplot(2,3,3)
scatter(62,VWE5a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
title('DMS 5')
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
xlim([61 65])
ylim([-0.2 2])
grid on
hold on
scatter(62,VWE5b_diff,50,'MarkerEdgeColor','[0 0.5 1]','Marker','x','linewidth',2)
scatter(62,VWE5c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
scatter(64,WWE5a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','o')
scatter(64,WWE5b_diff,50,'MarkerEdgeColor','[0 0.5 1]','Marker','x','LineWidth',2)
scatter(64,WWE5c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[0 0.5 1]','Marker','diamond')
% sgtitle('Ohne Wasserbewegung')
subplot(2,3,4)
scatter(62,VEM3a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
title('DMS 3')
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
ylim([-0.2 2])
grid on
hold on
scatter(62,VEM3b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','linewidth',2)
scatter(62,VEM3c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
scatter(64,WEM3a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
scatter(64,WEM3b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','LineWidth',2)
scatter(64,WEM3c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
subplot(2,3,5)
scatter(62,VEM4a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
ylim([-0.2 2])
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
title({'Mit Wasserbewegung','DMS 4'}) %%%%%%%%%%%%%%%%%%%%
grid on
hold on
scatter(62,VEM4b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','linewidth',2)
scatter(62,VEM4c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
scatter(64,WEM4a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
scatter(64,WEM4b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','LineWidth',2)
scatter(64,WEM4c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
subplot(2,3,6)
scatter(62,VEM5a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
xlim([61.5 64.5])
xticks([62 64])
xticklabels({'62','64'})
ylim([-0.2 2])
xlabel("Bauteilnummer")
ylabel("Spannung [MPa]")
title('DMS 5')
grid on
hold on
scatter(62,VEM5b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','linewidth',2)
scatter(62,VEM5c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
scatter(64,WEM5a_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','o')
scatter(64,WEM5b_diff,50,'MarkerEdgeColor','[1 0.2 0.2]','Marker','x','LineWidth',2)
scatter(64,WEM5c_diff,50,'MarkerEdgeColor','[0 0 0]','MarkerFaceColor','[1 0.2 0.2]','Marker','diamond')
fname = 'Kennwerte_Drifttest_Vorbereitung_Forschungswerkstatt';
picturewidth = 20; % set this parameter and keep it forever
hw_ratio = 0.7; % feel free to play with this ratio
set(findall(hfig,'-property','FontSize'),'FontSize',15) % adjust fontsize to your document
hold off
set(findall(hfig,'-property','Interpreter'),'Interpreter','latex')
set(findall(hfig,'-property','TickLabelInterpreter'),'TickLabelInterpreter','latex')
set(hfig,'Units','centimeters','Position',[3 3 picturewidth hw_ratio*picturewidth])
pos = get(hfig,'Position');
set(hfig,'PaperPositionMode','Auto','PaperUnits','centimeters','PaperSize',[pos(3), pos(4)])
%print(hfig,fname,'-dpdf','-painters','-fillpage')
I can't test it as I dont have VEM3a_diff etc.
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!