【问题标题】:Subplots are different sizes子图大小不同
【发布时间】:2020-12-04 14:31:20
【问题描述】:

我创建带有 5x3 子图的图形,每次迭代,每列再添加 3 个图形,每次迭代,前三个图缩小一点。

这是我的代码:

for i=1:4%for every station
   figure
    for j=1:sSelect %for every storm
        Hm0=eval(strcat('Hm0',Wavenames(i),'C'));%create data
        Tz=eval(strcat('Tz',Wavenames(i),'C'));
        Tp=eval(strcat('Tp',Wavenames(i),'C'));
        Ti=numericdates.(Wavenames(i));
        ix=Ti>Selectnum(j,1)-numMore & Ti<Selectnum(j,2)+numMore; %index of dates numMore hours before and after the storm
        
        Hm0Plot=Hm0(ix); %create data that needs to be plotted
        TzPlot=Tz(ix);
        TpPlot=Tp(ix);
        TPlot= datetime(Ti(ix),'ConvertFrom','datenum');%dates
        
        if ~isempty(TPlot) 
            
            subplot(3,5,j)
            plot(TPlot,Hm0Plot)
            xlabel('Date')
            ylabel('Hm0 (m)')
            xtickformat('dd-MM-yyyy HH:mm:ss')
         
            subplot(3,5,j+5)
            plot(TPlot,TzPlot)
            xtickformat('dd-MM-yyyy HH:mm:ss')
            xlabel('Date')
            ylabel('Tz0 (1/s)')


            subplot(3,5,j+10)
            plot(TPlot,TpPlot)
      xtickformat('dd-MM-yyyy HH:mm:ss')
            xlabel('Date')
            ylabel('Tp (1/s)')

            suptitle(Wavenames(i))
        end
    end
end

这会创建 4 个具有相同问题的图形,如下所示:

如何使所有子图的大小相同?

【问题讨论】:

  • 这看起来很奇怪,从来没有见过这样的结果。你用的是什么版本的MATLAB?如果这在最新版本中可以重现,您应该提交错误报告。
  • 尝试删除日期标签 (xlabel) 看看是否能暂时修复它
  • @CrisLuengo matlab R2020a
  • @AnderBiguri 这不是 xlabel 的问题。但你确实给了我一个想法。显然,这是因为我绘制了 4 次字幕。如果我从循环中删除它(见答案)我会解决问题
  • 与您的问题无关,但如果您有 R2018b 或更高版本,最好使用 sgtitlesuptitle 需要生物信息学工具箱

标签: matlab subplot


【解决方案1】:

这是因为命令suptitle 在循环中。如果我把它放在循环之外,它就可以工作。

for i=1:4%for every station


 figure
    for j=1:sSelect %for every storm
        Hm0=eval(strcat('Hm0',Wavenames(i),'C'));%Hm0BanyulsC
        Tz=eval(strcat('Tz',Wavenames(i),'C'));%TzBanyulsC
        Tp=eval(strcat('Tp',Wavenames(i),'C'));%TpBanyulsC
        Ti=numericdates.(Wavenames(i));
        ix=Ti>Selectnum(j,1)-numMore & Ti<Selectnum(j,2)+numMore; %index of dates numMore hours before and after the storm
    
    Hm0Plot=Hm0(ix);
    TzPlot=Tz(ix);
    TpPlot=Tp(ix);
    TPlot= datetime(Ti(ix),'ConvertFrom','datenum');
    
    if ~isempty(TPlot)
        
        subplot(3,5,j)
        plot(TPlot,Hm0Plot)
        xlabel('Date')
        ylabel('Hm0 (m)')
        xtickformat('dd-MM-yyyy')
      %  title(strcat('Storm',string(j)))

        subplot(3,5,j+5)
        plot(TPlot,TzPlot)
        xtickformat('dd-MM-yyyy')
        xlabel('Date')
        ylabel('Tz0 (1/s)')


        subplot(3,5,j+10)
        plot(TPlot,TpPlot)
        xtickformat('dd-MM-yyyy')
        xlabel('Date')
        ylabel('Tp (1/s)')

       
    end
    
end
suptitle(Wavenames(i))
end

【讨论】:

    猜你喜欢
    • 2021-08-05
    • 1970-01-01
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    相关资源
    最近更新 更多