Matlab shrinking subplot graphs when running the code
이전 댓글 표시
Everytime I run my code, the graphs I have shrink.
figure(100);clf;
or = [0.8500, 0.3250, 0.0980];
ye = [0.9290, 0.6940, 0.1250];
bl = [0, 0.4470, 0.7410];
vec = [or;ye;bl];
clr = 'rgb';
sz = 14;
yname(1).s = '\mu_s [cm^{-1}]';ytitle(1).s = 'Scattering';
yname(2).s = 'g [-]';ytitle(2).s = 'Anisiotropy';
yname(3).s = '\mu_s'' [cm^{-1}]';ytitle(3).s = 'Reduced Scattering';
ymax = [3000 1 400];
for k=1:3
subplot(3,1,k)
for j=1:length(diadia)
plot(lambdalambda, musgp(:,j,k),'-','color',vec(j,:),'linewidth',1)
hold on
y = ymax(k); dy = y/10; x = mean(lambdalambda);
text(x,y-dy*j,sprintf('dia = %0.3f um', diadia(j)), ...
'fontsize',sz, 'color',vec(j,:))
end%j
set(gca,'fontsize',sz)
xlabel('wavelength \lambda [\mum]')
ylabel(yname(k).s)
title(ytitle(k).s, 'fontsize',14)
end%k
is there a way I can make it so it does not shrink, or how would I separate the figure into three plots if this is not possible?
댓글 수: 3
Walter Roberson
2020년 7월 15일
Shrinking with regard to previous runs, so each run is smaller on the screen?
Or do you mean that the plots are smaller than you would prefer but that they are consistent size?
Your fontsize for your axes is one thing that is causing the plots to be small.
Rachel Fetter
2020년 7월 16일
Bjorn Gustavsson
2020년 7월 17일
Would it be possible for you to share the data producing your problematic figure?
답변 (1개)
Bjorn Gustavsson
2020년 7월 16일
Sometimes that (used to) happen, as far as I understood it had something to do with repeated plotting (possibly with titles and labels). You might avoid that by plotting all curves at once. Perhaps something like this:
for k=1:3
subplot(3,1,k)
j=1:length(diadia);
phK{k} = plot(lambdalambda,squeeze(musgp(:,j,k)),'-','color','linewidth',1);
hold on
y = ymax(k); dy = y/10; x = mean(lambdalambda);
text(x,y-dy*j,sprintf('dia = %0.3f um', diadia(j)), ...
'fontsize',sz, 'color',vec(j,:))
set(gca,'fontsize',sz)
xlabel('wavelength \lambda [\mum]')
ylabel(yname(k).s)
title(ytitle(k).s, 'fontsize',14)
end%k
for k = 1:3,
for j = 1:size(phK{k})
set(phK{k}(j),'color',vec(j,:));
end
end
HTH
댓글 수: 4
Rachel Fetter
2020년 7월 16일
Bjorn Gustavsson
2020년 7월 16일
That shoult not be the cause of the error. It is allowed to grow arrays dynamically in matlab - it is preferable not to since it is a comparatively costly operation to allocate space for a slightly larger array and copy data to that array. Here, we're talking about growing a call-array with 3 elements which is unproblematic.
The error is in the latter part of the argument-list, I goofed when modifying your code. It should be like this:
for k = 3:-1:1 % Changed to order of the loop to create the full phK-array first time
subplot(3,1,k)
j = 1:length(diadia); % Could be moved outside of the loop
phK{k} = plot(lambdalambda,squeeze(musgp(:,j,k)),'-','linewidth',1);
hold on
y = ymax(k); dy = y/10; x = mean(lambdalambda);
% Lets move this text to
% text(x,y-dy*j,sprintf('dia = %0.3f um', diadia(j)), ...
% 'fontsize',sz, 'color',vec(j,:))
set(gca,'fontsize',sz)
xlabel('wavelength \lambda [\mum]')
ylabel(yname(k).s)
title(ytitle(k).s, 'fontsize',14)
end%k
for j = 3:-1:1
l_str{j} = sprintf('dia = %0.3f um', diadia(j));
end
for k = 1:3,
for j = 1:size(phK{k})
set(phK{k}(j),'color',vec(j,:));
end
legend(phK{k},l_str,'box','off')
end
If you keep the outputs from the legend-call you can set and modify the text properties from the second output argument.
HTH
Rachel Fetter
2020년 7월 16일
Bjorn Gustavsson
2020년 7월 16일
Hm, (when I encounter this problem, I typically solve it irritated and on an exception-by-exception base so no record of what have worked...) what if you try to remove all the titling and labeling (or at least the resising of everything) and put that in separately at the end?
There is also a vague tingling of a memory that I've managed to the axes to get in shape by manually resizing the figure window.
Another, design-take on your figure: since you have the same range in wavelength in all subplots, you might consider only adding the xlabel to the bottom subplot - that will help save you some real-estate for the plots. Now, this is not my task or place to question your design/taste, but this is how I get more graph and less repeated text in my figures.
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!