Python(matplotlib)での論文用に使えるグラフの作り方を種類ごとにまとめました。
目次
「論文用グラフの作り方」の使い方
サンプル画像の下のコードを押していただくと,ソースコードが表示されます。
コピペでサンプル画像が作れます。
コピペをした後に,dataの部分とその他のカスタマイズを変更して使うことをおすすめします。
論文用グラフのおすすめの色
論文のグラフは誰が見ても同じ理解ができるようにモノトーンで作ることが好ましいと思います。
私がよく使う色をご紹介します。
色名 | RGB | 16進数 |
---|---|---|
黒 | (0,0,0) | #000000 |
灰色1 | (61,60,60) | #3d3c3c |
灰色2 | (133,132,132) | #858584 |
灰色3 | (182,182,182) | #b6b6b6 |
灰色4 | (224,224,224) | #e0e0e0 |
白 | (255,255,255) | #ffffff |
代表的なグラフ
下で紹介するグラフは,コードをコピペすると出力される画像です。
データの部分をご自身のものに変えて使用することができます。
詳しいカスタマイズについては,こちらの個別記事をご覧ください!
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://icochan1.net/wp-content/uploads/2023/02/c64c5ece666a6407486987541305a212-2-300x169.png)
【卒論】Pythonで論文用の棒グラフを綺麗に作成する
matplotlibでのグラフ作成は簡単ですが,そのまま論文で使う図となると物足りなさを感じます。 この記事では,論文用にグラフを綺麗に作成するための方法についてまとめ...
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://icochan1.net/wp-content/uploads/2023/02/a402c696bf493a873c765923653c07e6-1-300x169.png)
【卒論】Pythonで論文用の積み上げ棒グラフを綺麗に作成する
matplotlibでのグラフ作成は簡単ですが,そのまま論文で使う図となると物足りなさを感じます。 この記事では,論文用にグラフを綺麗に作成するための方法についてまとめ...
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://icochan1.net/wp-content/uploads/2023/02/d3f3f00cf1a7f0b7549c20d4afc63a1b-300x169.png)
【卒論】Pythonで論文用の折れ線グラフを綺麗に作成する
matplotlibでのグラフ作成は簡単ですが,そのまま論文で使う図となると物足りなさを感じます。 この記事では,論文用にグラフを綺麗に作成するための方法についてまとめ...
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://icochan1.net/wp-content/uploads/2023/02/9b4ccaedd1bef1dacccd44245c6b928f-300x169.png)
【卒論】Pythonで論文用の複数折れ線グラフを綺麗に作成する
matplotlibでのグラフ作成は簡単ですが,そのまま論文で使う図となると物足りなさを感じます。 この記事では,論文用にグラフを綺麗に作成するための方法についてまとめ...
あわせて読みたい
![](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
![](https://icochan1.net/wp-content/uploads/2023/02/7ecbec8b200a97f5b85a8a31ece4115c-300x169.png)
【卒論】Pythonで論文用の複合グラフを綺麗に作成する
matplotlibでのグラフ作成は簡単ですが,そのまま論文で使う図となると物足りなさを感じます。 この記事では,論文用にグラフを綺麗に作成するための方法についてまとめ...
棒グラフ
![](https://icochan1.net/wp-content/uploads/2023/02/Bar-1-1024x683.png)
コードはこちら
import matplotlib.pyplot as plt
import numpy as np
# 論文用の設定
# centimeters in inches
cm = 1/2.54
plt.rcParams['font.family'] = 'Helavetica' # font familyの設定
plt.rcParams['mathtext.fontset'] = 'stix' # math fontの設定
plt.rcParams["font.size"] = 12
plt.rcParams['figure.subplot.bottom'] = 0.15
plt.rcParams['figure.subplot.left'] = 0.15
plt.rcParams['axes.axisbelow'] = True
# データ作成
x = np.array([1, 2, 3, 4, 5])
data = np.array([30,50,90,40,70])
label = ["2018","2019","2020","2021","2022"]
# グラフの定義
fig = plt.figure(figsize=(12*cm, 8*cm),dpi=300)
ax = fig.add_subplot(1,1,1)
# グラフのプロット
ax.bar(x,
data,
tick_label=label,
align="center",
color="#000000",)
# 軸周りの設定
ax.set_ylim(0, 100)
ax.set_xlabel("Time")
ax.set_ylabel("Volume [XX]")
ax.grid(axis='y',linestyle='-', color='#e0e0e0')
fig.savefig("bar.png", format="png", dpi=300)
fig.show()
積み上げ棒グラフ
![](https://icochan1.net/wp-content/uploads/2023/02/bar_stacked-1-1024x837.png)
コードはこちら
import matplotlib.pyplot as plt
import numpy as np
# 論文用の設定
# centimeters in inches
cm = 1/2.54
plt.rcParams['font.family'] = 'Helavetica' # font familyの設定
plt.rcParams['mathtext.fontset'] = 'stix' # math fontの設定
plt.rcParams["font.size"] = 12
plt.rcParams['figure.subplot.bottom'] = 0.15
plt.rcParams['figure.subplot.left'] = 0.15
plt.rcParams['axes.axisbelow'] = True
# データ作成
x = np.array([1, 2, 3, 4, 5])
data = np.array([[70,50,30],
[30,40,30],
[50,90,40],
[60,40,50],
[30,40,50]])
label = ["2018","2019","2020","2021","2022"]
# グラフの定義
fig = plt.figure(figsize=(12*cm, 8*cm),dpi=300)
ax = fig.add_subplot(1,1,1)
# グラフのプロット1
B1 = ax.bar(x,
data[:,0],
tick_label=label,
align="center",
color="#000000")
# グラフのプロット2
B2 = ax.bar(x,
data[:,1],
bottom=np.sum(data[:,0:1],axis=1),
tick_label=label,
align="center",
color="#858584")
# グラフのプロット3
B3 = ax.bar(x,
data[:,2],
bottom=np.sum(data[:,0:2],axis=1),
tick_label=label,
align="center",
color="#3d3c3c")
# 軸周りの設定
ax.set_ylim(0, 200)
ax.set_xlabel("Time")
ax.set_ylabel("Volume [XX]")
ax.grid(axis='y',linestyle='-', color='#e0e0e0')
# 凡例の設定
plt.legend((B1[0], B2[0], B3[0]), ("bar1", "bar2", "bar3"),
loc='lower center',
bbox_to_anchor=(.5, 1.1),
ncol=3,
fancybox=False,
edgecolor="k")
#セーブ
fig.savefig("bar_stacked.png", format="png", dpi=300, bbox_inches='tight')
fig.show()
折れ線グラフ
![](https://icochan1.net/wp-content/uploads/2023/02/Plot-1024x683.png)
コードはこちら
import matplotlib.pyplot as plt
import numpy as np
# 論文用の設定
# centimeters in inches
cm = 1/2.54
plt.rcParams['font.family'] = 'Helavetica' # font familyの設定
plt.rcParams['mathtext.fontset'] = 'stix' # math fontの設定
plt.rcParams["font.size"] = 12
plt.rcParams['figure.subplot.bottom'] = 0.15
plt.rcParams['figure.subplot.left'] = 0.15
plt.rcParams['axes.axisbelow'] = True
# データ作成
x = np.array([1, 2, 3, 4, 5])
data = np.array([30,50,90,40,70])
label = ["2018","2019","2020","2021","2022"]
# グラフの定義
fig = plt.figure(figsize=(12*cm, 8*cm),dpi=300)
ax = fig.add_subplot(1,1,1)
# グラフのプロット
ax.plot(x,
data,
label=label,
color="#000000",
marker=".",
markersize = 10)
# 軸周りの設定
ax.set_ylim(0, 100)
ax.set_xlabel("Time")
ax.set_ylabel("Volume [XX]")
ax.grid(axis='y',linestyle='-', color='#e0e0e0')
fig.savefig("plot.png", format="png", dpi=300)
fig.show()
複数系列の折れ線グラフ
![](https://icochan1.net/wp-content/uploads/2023/02/plot_multi-1024x837.png)
コードはこちら
import matplotlib.pyplot as plt
import numpy as np
# 論文用の設定
# centimeters in inches
cm = 1/2.54
plt.rcParams['font.family'] = 'Helavetica' # font familyの設定
plt.rcParams['mathtext.fontset'] = 'stix' # math fontの設定
plt.rcParams["font.size"] = 12
plt.rcParams['figure.subplot.bottom'] = 0.15
plt.rcParams['figure.subplot.left'] = 0.15
plt.rcParams['axes.axisbelow'] = True
# データ作成
x = np.array([1, 2, 3, 4, 5])
data = np.array([[30,50,20],
[90,40,30],
[70,80,50],
[70,40,35],
[10,50,90]])
label = ["2018","2019","2020","2021","2022"]
# グラフの定義
fig = plt.figure(figsize=(12*cm, 8*cm),dpi=300)
ax = fig.add_subplot(1,1,1)
# グラフのプロット
P1 = ax.plot(x,
data[:,0],
label=label,
color="#000000",
marker=".",
markersize = 10)
P2 = ax.plot(x,
data[:,1],
label=label,
color="#000000",
marker="^",
markerfacecolor='#ffffff',
markeredgecolor="#000000",
markersize = 6)
P3 = ax.plot(x,
data[:,2],
label=label,
color="#000000",
ls="--",
marker="x",
markersize = 6)
# 凡例の設定
plt.legend((P1[0], P2[0], P3[0]), ("plot1", "plot2", "plot3"),
loc='lower center',
bbox_to_anchor=(.5, 1.1),
ncol=3,
fancybox=False,
edgecolor="k")
# 軸周りの設定
ax.set_ylim(0, 100)
ax.set_xlabel("Time")
ax.set_ylabel("Volume [XX]")
ax.grid(axis='y',linestyle='-', color='#e0e0e0')
fig.savefig("plot_multi.png", format="png", dpi=300, bbox_inches='tight')
fig.show()
複合グラフ
![](https://icochan1.net/wp-content/uploads/2023/02/complex-2-1024x732.png)
コードはこちら
import matplotlib.pyplot as plt
import numpy as np
# 論文用の設定
# centimeters in inches
cm = 1/2.54
plt.rcParams['font.family'] = 'Helavetica' # font familyの設定
plt.rcParams['mathtext.fontset'] = 'stix' # math fontの設定
plt.rcParams["font.size"] = 12
plt.rcParams['figure.subplot.bottom'] = 0.15
plt.rcParams['figure.subplot.left'] = 0.15
plt.rcParams['axes.axisbelow'] = True
# データ作成
x = np.array([1, 2, 3, 4, 5])
data1 = [30,50,90,40,70];
data2 = [50,70,50,30,80];
label = ["2018","2019","2020","2021","2022"]
# グラフの定義
fig = plt.figure(figsize=(12*cm, 8*cm),dpi=300)
ax_left = fig.add_subplot(1,1,1)
ax_right = ax_left.twinx()
# グラフのプロット
# 左軸(折れ線)
P = ax_left.plot(x,
data1,
label=label,
color="#000000",
marker="^",
markerfacecolor='#ffffff',
markeredgecolor="#000000",
markersize = 6)
# 右軸(棒グラフ)
B = ax_left.bar(x,
data2,
tick_label=label,
align="center",
color="#858584")
# 凡例の設定
plt.legend((P[0], B[0]), ("plot", "bar"),
loc='lower center',
bbox_to_anchor=(.5, 1.1),
ncol=3,
fancybox=False,
edgecolor="k")
# 軸周りの設定
ax_left.set_ylim(0, 100)
ax_left.set_xlabel("Time")
ax_left.set_ylabel("Volume1 [XX]")
ax_right.set_ylim(0, 100)
ax_right.set_xlabel("Time")
ax_right.set_ylabel("Volume2 [XX]")
ax_left.grid(axis='y',linestyle='-', color='#e0e0e0')
fig.savefig("complex.png", format="png", dpi=300, bbox_inches='tight')
fig.show()
コメント