ぷそさんのプログラミング研究所

【Matlab】論文用グラフの作り方|6種類のグラフで紹介

Matlabのグラフの作り方をグラフの種類ごとにまとめました。

サイズに関しての設定はこちらの記事で紹介しています。

あわせて読みたい
【卒論】論文用の棒グラフを綺麗に作成する|Matlab matlabでのグラフ作成は設定が多く大変です。 そのままの設定でもグラフは作成できますが,論文用に綺麗に作成するための方法についてまとめました。 卒論や修論用に参...
目次

「論文用グラフの作り方」の使い方

サンプル画像の下のコードを押していただくと,ソースコードが表示されます。

コピペでサンプル画像が作れます。

コピペをした後に,dataの部分とその他のカスタマイズを変更して使うことをおすすめします。

論文用グラフのおすすめの色

論文のグラフは誰が見ても同じ理解ができるようにモノトーンで作ることが好ましいと思います。

私がよく使う色をご紹介します。

RGB: 0 0 0
16進数:#000000

RGB: 61 60 60
16進数:#3d3c3c

RGB: 133 132 132
16進数:#858584

RGB: 182 182 182
16進数:#b6b6b6

RGB: 224 224 224
16進数:#e0e0e0

RGB: 255 255 255
16進数:#ffffff

棒グラフ

SAMPLE
clear;
%% データ作成
data = [30 50 90 40 70];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 15 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
B = bar(data);

% 棒グラフの色をつける
B.FaceColor = [ 0/255  0/255  0/255]; 

% 軸の設定
xlim([0 6])
ylim([0 100])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume [XX]') 

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'Bar.png')

積み上げ棒グラフ

SAMPLE
clear;
%% データ作成
data = [[70 50 30]
        [30 40 30]
        [50 90 40]
        [60 40 50]
        [30 40 50]];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 15 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
B = bar(data,0.6,"stacked");

% 棒グラフの色をつける
B(1).FaceColor = [ 0/255  0/255  0/255]; 
B(2).FaceColor = [133/255 132/255 132/255]; 
B(3).FaceColor = [ 50/255  52/255  53/255]; 

% 軸の設定
xlim([0.5 5.5])
ylim([0 200])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume [XX]') 

legend('bar1','bar2','bar3','Location','northoutside','Orientation','horizontal','NumColumns',3)

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'Bar_stacked.png')

横ならび棒グラフ

SAMPLE
clear;
%% データ作成
data = [[30 40 30]
        [50 90 40]
        [60 40 50]
        [30 40 50]];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 15 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
B = bar(data);

% 棒グラフの色をつける
B(1).FaceColor = [ 0/255  0/255  0/255]; 
B(2).FaceColor = [133/255 132/255 132/255]; 
B(3).FaceColor = [ 50/255  52/255  53/255]; 

% 軸の設定
xlim([0.5 4.5])
ylim([0 100])
xticks([1 2 3 4])
xticklabels({'2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume [XX]') 

legend('bar1','bar2','bar3','Location','northoutside','Orientation','horizontal','NumColumns',3)

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'Bar_parallel.png')

折れ線グラフ

SAMPLE
clear;
%% データ作成
data = [30 50 90 40 70];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 15 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
P = plot(data,'-o');

% グラフの色をつける
P.LineWidth = 3; 
P.Color = [0/255 0/255 0/255]; 
P.MarkerFaceColor = 'k';
P.MarkerSize = 8;

% 軸の設定
xlim([0.5 5.5])
ylim([0 100])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume [XX]') 

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'Plot.png')

複数の折れ線グラフ

SAMPLE
clear;
%% データ作成
data = [[30 50] 
        [90 40] 
        [70 80]
        [70 40] 
        [10 50]];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 15 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
P = plot(data,'-o');

% グラフの色をつける
P(1).LineWidth = 3; 
P(1).Color = [0/255 0/255 0/255]; 
P(1).MarkerFaceColor = 'k';
P(1).MarkerSize = 8;

P(2).LineWidth = 2; 
P(2).Color = [0/255 0/255 0/255]; 
P(2).MarkerFaceColor = [1 1 1];
P(2).MarkerSize = 8;

% 軸の設定
xlim([0.5 5.5])
ylim([0 100])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume [XX]') 

legend('plot1','plot2','Location','northoutside','Orientation','horizontal','NumColumns',2)

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'Plot_multi.png')

複合グラフ

SAMPLE
clear;
%% データ作成
data1 = [30 50 90 40 70];
data2 = [50 70 50 30 80];

%% グラフの大きさ定義
f = gcf;
f.Units = 'centimeters'; 
f.Position = [0 0 18 12];
f.Units = 'normalized';   %規格化単位に戻す

ax = gca;
ax.Units = 'centimeters'; 
ax.Position = [2 2 14 9.5]; %サイズ指定
ax.Units = 'normalized';

%% グラフ作成
% 棒グラフ
yyaxis left
B = bar(data2,0.6);

% 棒グラフの色をつける
B.FaceColor = [133/255 132/255 132/255]; 

% 軸の設定
xlim([0.5 5.5])
ylim([0 100])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume1 [XX]') 


% 折れ線グラフ
yyaxis right
P = plot(data1,'-o');

% グラフの色をつける
P.LineWidth = 3; 
P.Color = "k"; 
P.MarkerFaceColor = [255/255 255/255 255/255];
P.MarkerSize = 8;


% 軸の設定
xlim([0.5 5.5])
ylim([0 100])
xticks([1 2 3 4 5])
xticklabels({'2018','2019','2020','2021','2022'})
xlabel('Time') 
ylabel('Volume2 [XX]') 

legend('bar','plot','Location','northoutside','Orientation','horizontal','NumColumns',2)

ax.FontSize = 14;
ax.YAxis(1).Color = [0 0 0];
ax.YAxis(2).Color = [0 0 0];
ax.YGrid = 'on';

saveas(f,'complex.png')
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

このブログでは,PythonやLaTeXの使い方などを紹介しています!
仕事でも趣味でもプログラミングをしています。
ブログは2022年8月にスタートしました。
【経歴】東京大学大学院修了→大手IT企業勤務

コメント

コメントする

目次