% 総務省 統計局・統計研修所HP内>世界の統計-第2章 人 口 % http://www.stat.go.jp/data/sekai/02.htmのエクセルファイルより, % 人口推移を折れ線グラフとして表示する. clear all; close all; % 読み込ませるEXCELファイル EXCELFILE = '0201.xls'; % EXCELファイルのチェック [a,sheets] = xlsfinfo(EXCELFILE); if ~strcmp(a,'Microsoft Excel Spreadsheet') error('0201.xlsはMicrosoft Excelのシートを含まないファイルです.'); end; % EXCELファイルからのデータ読み込み [data, tdata] = xlsread(EXCELFILE,1); %=================== 数値データの処理 % 数値データの不要なデータ削除 data = data(:,1:8); rows = find(isnan(data(:,1))); data(rows,:) = []; % 年度ラベルの抽出と数値データからの削除 years = int16(data(:,1)); data(:,1) = []; %=================== テキストデータの処理 % グラフタイトルの抽出 graph_title = tdata(1,1); % 不要データ削除 tdata = tdata(:,1:8); rows = strcmp(tdata(:,2),''); tdata(rows,:)=[]; tdata(3,:)=[]; % 「将来推計」の文字の削除 % グラフの凡例用テキストと軸ラベルの抽出 tdata(strcmp(tdata,'')) = []; labelX = tdata(1); labelY = strcat('人口 ',tdata(3)); tdata([1,3]) = []; legends = regexprep(tdata,'\n',''); % なぜか'アフ\nリカ'となっているので改行を削除 %=================== グラフ化の処理 nowind=find(years==2004); ind1=1:nowind; % 2004度までのインデクス ind2=nowind:length(years); % 2004度以降のインデクス % FIGURE ハンドルの生成 scrsz = get(0,'ScreenSize'); figH = figure('PaperSize', [20 10],'InvertHardcopy', 'off', 'Color', [1 1 1], 'Position', [200 scrsz(4)-620 560 520]); figsz = get(figH,'Position'); % 軸作成 ax = axes('Parent', figH, 'PlotBoxAspectRatio', [1 1 1]); box('on'); hold('all'); % 世界全体の変化グラフ ----- grH1 = subplot(1,2,1); subplot(grH1), plot(years(ind1), data(ind1,1), 'b-' ... ,years(ind2), data(ind2,1), 'b:' ... ); set(grH1,'Position',[60/figsz(3) 35/figsz(4) 200/figsz(3) 430/figsz(4)]); % グラフタイトル title('世界全体の人口変化','FontSize',10); % 軸ラベル xlabel(labelX,'FontSize',9); ylabel(labelY,'FontSize',9); % 凡例の表示 lh = legend(legends(1), 'Location', 'NorthWest', 'FontSize',8, 'Box', 'off', 'Color', 'none', 'EdgeColor', [1 1 1]); % 地域ごとの人口変化のグラフ ----- grH2 = subplot(1,2,2); subplot(grH2), plot(years(ind1), data(ind1,2), 'm-' ... ,years(ind1), data(ind1,3), 'k-' ... ,years(ind1), data(ind1,4), 'b-' ... ,years(ind1), data(ind1,5), 'r-' ... ,years(ind1), data(ind1,6), 'g-' ... ,years(ind1), data(ind1,7), 'c-' ... ,years(ind2), data(ind2,2), 'm:' ... ,years(ind2), data(ind2,3), 'k:' ... ,years(ind2), data(ind2,4), 'b:' ... ,years(ind2), data(ind2,5), 'r:' ... ,years(ind2), data(ind2,6), 'g:' ... ,years(ind2), data(ind2,7), 'c:' ... ); set(grH2,'Position',[340/figsz(3) 35/figsz(4) 200/figsz(3) 430/figsz(4)]); % グラフタイトル title('地域ごとの人口変化','FontSize',10); % 軸ラベル xlabel(labelX,'FontSize',9); ylabel(labelY,'FontSize',9); % 凡例の表示 lh = legend(legends(2:end), 'Location', 'NorthWest', 'FontSize',8, 'Box', 'off', 'Color', 'none', 'EdgeColor', [1 1 1]); % グラフ全体のタイトル追加 annotation(figH,'textbox','String',graph_title,'HorizontalAlignment','center', 'FontSize',12, 'EdgeColor','none', 'Position',[0 1-20/figsz(4) 1 20/figsz(4)], 'FitHeightToText', 'on');