The question about subfigure size and property loop scripts
이전 댓글 표시
- There are many similar subfigure property in my scripts, how can I simplify it?
- How could I change the size of each subfigure? It looks a little crowded, I want them distribute more evenly on my figure.
load('C:\EEG_OVGU\F01_spectra\F01_spectra_01figure\EAF1_mean_spectra.mat')
figure('Position', [25 50 1200 880]) % [left bottom width height]
set(gcf,'color',[1 1 1]);
% ED1
% get(gcf)
subplot(3,6,1);
x = 1:45;
h1 = plot(x, ME_ED1_all); % h1 = plot(x, ME_ED1_all(1,1:30));
hold on
h2 = plot(x, MR_ED1_all);
h01 = plot([3,3],[0,7],'--','color',[0.5 0.5 0.5]); % 画竖线 plot([x1,x2],[y1,y2])
h02 = plot([7,7],[0,7],'--','color',[0.5 0.5 0.5]);
h03 = plot([11,11],[0,7],'--','color',[0.5 0.5 0.5]);
h04 = plot([14,14],[0,7],'--','color',[0.5 0.5 0.5]);
h05 = plot([30,30],[0,7],'--','color',[0.5 0.5 0.5]);
xticks([3 7 11 14 30]);
% xticklabels({'Delta','Theta','Alpha I','Alpha II','Beta'})
% xticklabels({'\delta','\theta','\alphaI','\alphaII','\beta'})
legend([h1,h2],'Eye yoga group', 'Reading group','FontSize',7, 'box', 'off');
ax = gca;
ax.XAxis.FontSize = 7; ax.YAxis.FontSize = 7;
title('ED1 all region');
xlabel('Frequency(Hz)');
ylabel('Spectral Power(µV)');
set(gca,'XLim',[0, 45],'YLim',[0, 7]);
set(h1,'LineStyle','-','LineWidth',1.5,'Color',[0.85,0.45,0.42]);
set(h2,'LineStyle','-','LineWidth',1.5,'Color',[0.45,0.5,0.7]);
% get(legend)
hold off
subplot(3,6,2);
x = 1:45;
h3 = plot(x, ME_ED1_frontal);
hold on
h4 = plot(x, MR_ED1_frontal);
h01 = plot([3,3],[0,7],'--','color',[0.5 0.5 0.5]); % 画竖线 plot([x1,x2],[y1,y2])
h02 = plot([7,7],[0,7],'--','color',[0.5 0.5 0.5]);
h03 = plot([11,11],[0,7],'--','color',[0.5 0.5 0.5]);
h04 = plot([14,14],[0,7],'--','color',[0.5 0.5 0.5]);
h05 = plot([30,30],[0,7],'--','color',[0.5 0.5 0.5]);
xticks([3 7 11 14 30]);
% xticklabels({'Delta','Theta','Alpha I','Alpha II','Beta'})
legend([h1,h2],'Eye yoga group', 'Reading group','FontSize',7, 'box', 'off');
ax = gca;
ax.XAxis.FontSize = 7; ax.YAxis.FontSize = 7;
title('ED1 frontal region');
set(gca,'XLim',[0, 45],'YLim',[0, 7]);
set(h3,'LineStyle','-','LineWidth',1.5,'Color',[0.85,0.45,0.42]);
set(h4,'LineStyle','-','LineWidth',1.5,'Color',[0.45,0.5,0.7]);
hold off
답변 (1개)
I would create a function that accepts data (and possibly an axes handle) and performs the necessary setup. The example below requires the user to pass the axes into which to plot, the data to plot, and the label to use for the legend into it and uses the same settings for the axes color, line style and size, and marker and marker size.
ax1 = subplot(3, 1, 1);
x = 0:360;
plotAndConfigure(ax1, x, sind(x), 'Sine');
ax2 = subplot(3, 1, 2);
plotAndConfigure(ax2, x, cosd(x), 'Cosine');
ax3 = subplot(3, 1, 3);
plotAndConfigure(ax3, x, tand(x), 'Tangent');
function plotAndConfigure(theaxes, xdata, ydata, label)
h = plot(theaxes, xdata, ydata, ':*', ...
'MarkerIndices', 1:30:length(xdata), ...
'DisplayName', label, ...
'LineWidth', 2);
theaxes.Color = 'c';
% Double the default marker size
h.MarkerSize = 2*h.MarkerSize;
legend show
end
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
