美文网首页
MATLAB中画直方图-正负分开

MATLAB中画直方图-正负分开

作者: 废柴随笔 | 来源:发表于2021-08-10 10:03 被阅读0次

    clear

    [xielv,R] = geotiffread('D:\data.tif');%读取线性趋势

    info=geotiffinfo('D:\data.tif');

    [m,n] = size(xielv);

    xielv = reshape(xielv,m*n,1);

    xielv_valid_zheng = xielv(xielv >= 0);  %正变化趋势

    [Num_zheng,xaxis_zheng] = hist(xielv_valid_zheng,50);

    b2=bar(xaxis_zheng,Num_zheng,0.5,'FaceColor',[71/255,145/255,186/255],'EdgeColor',[71/255,145/255,186/255])

    hold on

    xielv_valid_fu = xielv(xielv < 0);  %负变化趋势

    [Num_fu,xaxis_fu] = hist(xielv_valid_fu,80);

    b3=bar(xaxis_fu,Num_fu,0.5,'FaceColor',[218/255,103/255,81/255],'EdgeColor',[218/255,103/255,81/255])

    % set(gca,'XLim', [-0.05 0.03])

    % set(gca,'XTick', [-0.05 -0.04 -0.03 -0.02 -0.01 -0.005 0 0.005  0.01 0.015 0.02 0.03])

    % set(gca,'Xticklabel',{'-0.05','-0.04','-0.03','-0.02','-0.01','-0.005','0','0.005','0.01','0.015','0.02','0.03'})

    set(gca,'XLim', [-0.02 0.02])

    set(gca,'XTick', [ -0.02  -0.015 -0.01 -0.005 0 0.005  0.01 0.015 0.02 ])

    set(gca,'Xticklabel',{'-0.02','-0.015','-0.01','-0.005','0','0.005','0.01','0.015','0.02'})

    set(gca,'YLim', [0 400000])

    set(gca,'YTick',0:100000:400000)

    set(gca,'Yticklabel',{'0','1','2','3','4'})

    oldLabels = str2num(char(get(gca,'YTickLabel')));

    Yscale = 10^5;

    newLabels = num2str(oldLabels*Yscale);

    set(gca,'YTickLabel',newLabels,'YTickLabelMode','auto');

    set(gca,'FontSize',10)

    xlabel('NDVI变化趋势 yr^-^1');

    ylabel('频数');

    legend([b2,b3],'正趋势','负趋势')

    print(gcf,['D:\趋势直方图.tif'],'-dtiff','-r600');

    close     

    相关文章

      网友评论

          本文标题:MATLAB中画直方图-正负分开

          本文链接:https://www.haomeiwen.com/subject/csgdrltx.html