Matlab shrinking subplot graphs when running the code

16 ビュー (過去 30 日間)
Rachel Fetter
Rachel Fetter 2020 年 7 月 15 日
コメント済み: Bjorn Gustavsson 2020 年 7 月 17 日
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 件のコメント
Rachel Fetter
Rachel Fetter 2020 年 7 月 16 日
I mean the graphs start out a normal size with proper scaling when I first open the file and then when run it the data shrinks. For example, you can see on the image the the "dia" labels are all overlapping on each graph. I did play with font sizes and that is not the problem.
Bjorn Gustavsson
Bjorn Gustavsson 2020 年 7 月 17 日
Would it be possible for you to share the data producing your problematic figure?

サインインしてコメントする。

回答 (1 件)

Bjorn Gustavsson
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
Rachel Fetter 2020 年 7 月 16 日
Okay, this fixed the legend text, but the axis are still being condensed. I guess, I'm confused on what is actually happening to cause the issue.
Bjorn Gustavsson
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by