得到如下圖的條形圖
條形圖
處理代碼
% By Yang,2020/7/30
clear
dz = 'D:\GPP\tem_opt\result\tem_opt_min\raster\tem_opt_f.tif';% 數(shù)據(jù)地址
tem_opt = double(importdata(dz)); % 讀取tif文件逊笆,并轉(zhuǎn)換為doule類型
tem_opt(tem_opt == -9999) = NaN; % 非正常值設為NaN
num(1,1) = numel(find(tem_opt<5)); % 第一個柱子的數(shù)據(jù)
num(2,1) = numel(find(tem_opt>=5 & tem_opt<10));
num(3,1) = numel(find(tem_opt>=10 & tem_opt<15));
num(4,1) = numel(find(tem_opt>=15 & tem_opt<20));
num(5,1) = numel(find(tem_opt>=20 & tem_opt<25));
num(6,1) = numel(find(tem_opt>=25 & tem_opt<30));
num(7,1) = numel(find(tem_opt>=30)); % 第七個柱子的數(shù)據(jù)
num_all = sum(num); % 非NaN值像元總數(shù)
num_p = num/num_all*100; % 每個柱子所占總數(shù)的百分比
% 畫條形圖
pic = bar(num_p,'LineWidth',1.2); % LineWidth 線寬
% 設置不同條形柱子的顏色
pic.FaceColor = 'flat';
pic.CData(1,:) = [40/255,146/255,199/255]; % 普通RGB值除以255芬膝,得到的數(shù)字就是在MATLAB中顏色的值
pic.CData(2,:) = [129/255,179/255,171/255];
pic.CData(3,:) = [191/255,212/255,138/255];
pic.CData(4,:) = [250/255,250/255,100/255];
pic.CData(5,:) = [252/255,179/255,68/255];
pic.CData(6,:) = [247/255,110/255,42/255];
pic.CData(7,:) = [232/255,21/255,21/255];
hold on
ylabel('Percentage (%)','Fontname', 'Times New Roman','fontsize',24,'FontWeight','bold'); % 設置y軸標簽字體
set(gca, 'Fontname', 'Times New Roman','FontSize',16,'FontWeight','bold'); % 設置刻度字體
set(gca,'tickdir','out'); % 刻度線向外
set(gca,'xtick',[]); % X軸坐標取消
set(gca,'linewidth',1.4); % 坐標軸線寬
box off % 取消上右邊框
最終效果
效果圖
縮小放到空間圖里