LoginSignup
54
41

More than 1 year has passed since last update.

Python-SciencePlotsで論文用の図を作成してみた

Last updated at Posted at 2022-04-11

この記事について

  • pythonユーザーであれば可視化ツールmatplotlibの利用者は多いだろう。しかし論文用の「良い感じの図」を作成するには細かいパラメータをいじる必要があり手間がかかる。そこで今回はSciencePlotsという、簡易的に「良い感じの図」を出力してくれる拡張パッケージを紹介する。
  • 導入することで、NatureやIEEEの規定に従った図を簡単に作成することができる。

導入方法

SciencePlotsのインストール

公式PyPIページからインストールできる。
もしくは以下のコマンドを実行する。

pip install SciencePlots

latex関連パッケージのインストール

SciencePlotsはlatex環境で動作するため、以下のコマンドで必要パッケージをインストールする。

sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super

使い方

  • プログラム内で説明する。
import matplotlib.pyplot as plt
import numpy as np

#ここでスタイルを指定する
#今回は'science'と'ieee'を利用してみる
plt.style.use(['science','ieee'])

#適当に3Hzと4Hzの信号を作成
x = np.linspace(0,1,100)
y = np.sin(2*np.pi*3*x)
y2 = np.sin(2*np.pi*4*x)

#図の表示
fig = plt.figure()
ax = fig.add_subplot(1,1,1) 
ax.plot(x,y,label = '3 Hz') #3Hzの波を表示
ax.plot(x,y2,label = '4 Hz') #4Hzの波を表示
ax.legend(title = 'Sine Wave',loc = 'upper right',fancybox = False, frameon = True) #凡例の細かい設定
ax.set(xlabel = 'Time (s)') #x軸のラベル
ax.set(ylabel = 'Amplitude') #y軸のラベル
fig.show() 

実行結果

  • SciencePlotsの有無で出力結果を比較してみた。
  • 利用した場合だと自動的にフォント、破線、軸の間隔、アスペクト比等を設定してくれて「良い感じの図」になっている。

'science'と'ieee'スタイルを利用した場合

withscience.png

何も利用しない場合

withoutscience.png

補足

  • IEEEの会議等に提出する場合、図表は白黒で印刷したときに読みやすくなければならないとされている(IEEE公式:図の規定)。また図の幅を1段に収まるようにする必要がある。'ieee'スタイルを設定すると規定に従った図を出力してくれる。
  • SciencePlotsのgithubページに'science'+'何かしらのスタイル'の例が多数紹介されているので各自試してみてほしい。
54
41
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
41