suplot画图,共用colorbar,公用legend

% 读数据
inputdata = [];
[cols,rows] = size(inputdata);
% 先统计计算实部和小波方差
scale = 1:1:32; % 检测样本长度在50-100是,scale为32100以上是为64for n = 1:rows
    data = inputdata(:,n);
    data = zscore(data);
    %进行连续小波变换得到小波系数矩阵,选择复morlet小波函数
    wf = cwt(data,scale,'cmor1-1.5','plot');
    % 求得系数的实部及存储
    shibu = real(wf);
    SHIBU{n} = shibu; 
    
    % 计算小波方差
    mo = abs(wf);
    mofang = mo.^2;
    fangcha = mean(mofang,2);
    FC{n} = fangcha;
end

%% 画小波方差图
figure(1)
set(gcf,'Color','w') % 设置背景为白色底
txts = {('(a1)')  ('(a2)')  ('(a3)')  ('(a4)')  ('(a5)')  ('(b1)')  ('(b2)')  ('(b3)')  ('(b4)')} ;
txty = [0.7 1.3 0.7 0.52 0.7 0.85 0.9 0.7 0.7];
for i = 1:3  % 文件次序
    subplot('Position',[0.1+0.3*(i-1) 0.7 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    fc = FC{i};
    plot(fc,'dk-','linewidth',1.5)
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(32, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on; grid on
end

for i = 4:6  % 文件次序
    subplot('Position',[0.1+0.3*(i-4) 0.4 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    fc = FC{i};
    plot(fc,'dk-','linewidth',1.5)
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(32, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on; grid on
end

for i = 7:9  % 文件次序
    subplot('Position',[0.1+0.3*(i-7) 0.1 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    fc = FC{i};
    plot(fc,'dk-','linewidth',1.5)
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(32, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on; grid on
end

axes('position',[0.10,0.10,0.8,0.8],'Color','None','visible','off');  % 图中图!,重要,隐藏坐标轴
xlabel('Peirod (a)','Visible','on','FontName','Times New Roman','FontSize',16,'FontWeight','bold')
ylabel('Wavelet Variance','Visible','on','FontName','Times New Roman','FontSize',16,'FontWeight','bold')

%% 画小波实部图
figure(2)
set(gcf,'Color','w') % 设置背景为白色底
txts = {('(a1)')  ('(a2)')  ('(a3)')  ('(a4)')  ('(a5)')  ('(b1)')  ('(b2)')  ('(b3)')  ('(b4)')} ;
txty = [34 34 34 34 34 34 34 34 34];
for i = 1:3  % 文件次序
    subplot('Position',[0.1+0.27*(i-1) 0.7 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    shibu = SHIBU{i};
    contourf(shibu,5,'-','linewidth',1.0);
    set(gca,'xtick',[10:10:50],'xticklabel',[1973:10:2013]) % ( 知识点 ) 修改对应的坐标刻度 !!
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(2, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on; 
end

for i = 4:6  % 文件次序
    subplot('Position',[0.1+0.27*(i-4) 0.4 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    shibu = SHIBU{i};
    contourf(shibu,5,'-','linewidth',1.0);
    set(gca,'xtick',[10:10:50],'xticklabel',[1973:10:2013]) % 修改对应的坐标刻度 !!( 知识点 )
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(2, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on;
end

for i = 7:9  % 文件次序
    subplot('Position',[0.1+0.27*(i-7) 0.1 0.25 0.25]) % subplot('Position',[left bottom width height]),找位置
    shibu = SHIBU{i};
    contourf(shibu,5,'-','linewidth',1.0);
    set(gca,'xtick',[10:10:50],'xticklabel',[1973:10:2013]) % 修改对应的坐标刻度 !!( 知识点 )
    set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1);
    text(2, txty(i) ,txts(i) ,'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
    box on; 
end
% (知识点)重新设置colorbar的位置
colormap('jet'); 
colorbar('Position',[0.9 0.1 0.015 0.85],'LineWidth',1.0,'FontSize',12) % !!这里其实有问题,这个colorbar是画的最后一张图的colorbar,不能用于公共使用!
% 若需要共用应该根据全部图形的min和max确定colorbar的范围
hc=colormap(jet(10)) % 若将整个颜色等分10段,当然也可不分;
caxis([allmin,allmax]) % 找到全部子图的最小值和最大值替换allmin allmax
set(hc,'YTick',allmin:step:allmax) % 这个是等分情况下,设置上下边界和步长。
axes('position',[0.10,0.10,0.8,0.8],'Color','None','visible','off');  % 图中图!,重要,隐藏坐标轴
xlabel('Year','Visible','on','FontName','Times New Roman','FontSize',16,'FontWeight','bold')
ylabel('Period (a)','Visible','on','FontName','Times New Roman','FontSize',16,'FontWeight','bold')

小波方差
小波实部

公用legend

txt = {['(a1)'] ['(b1)'] ['(c1)'] ['(d1)']};
txtloc = [3.7, 1.7, 2.8, 3.5]
for    i =1:4
        axmk = subplot('Position',[0.1+(i-1)*0.22, 0.7, 0.17, 0.20]);
        line([year(1), year(end)], [0,0], 'color','k','linestyle','-.','linewidth',1)
        line([year(1), year(end)], [-1.96,-1.96], 'color','k','linestyle',':','linewidth',1)
        hcen = line([year(1), year(end)], [1.96,   1.96], 'color','k','linestyle',':','linewidth',1)
        set(gca,'FontName','Times New Roman','FontSize',12,'FontWeight','bold','LineWidth',1)
        hold on; box on
        huf=plot(year,mkdata(:, 2*i-1), 'color','red','linestyle','-','linewidth',2)
        hub= plot(year,mkdata(:, 2*i), 'color','k','linestyle','-','linewidth',2);
        text(2008, txtloc(i), txt(i), 'color','k','FontName','Times New Roman','FontSize',12,'FontWeight','bold')
        xlabel('Year');  ylabel('Statistical Value')
end
        lgd = legend([hcen,huf,hub],'95% confidence level','UF','UB','Location','NorthOutside','orientation','horizontal')
        lgd.Position = [0.16 0.90 0.7 0.05]  % 公用legend
        lgd.Position = [0.16 0.90 0.7 0.05]  % 公用legend

在这里插入图片描述

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大雨海深

感谢您的支持和鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值