4
7

More than 3 years have passed since last update.

PythonでAdobe illustratorで編集できるfigureを作成する

Last updated at Posted at 2019-10-20

Jupyter notebookでの作図を論文のFigureに使用したい場合,最終的にはIllustratorでの加工が必要になるときがあります。

そのときのために,Illustratorでの編集が可能なPDFファイルの作成の方法です。
リンク1, リンク2

illustrator-editable-figure.py
import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42

#複数ページをPDF保存する際に必要なmodule
from matplotlib.backends.backend_pdf import PdfPages

.............
.............
.............

# 保存の際に下記。見切りが発生する場合は,さらにplt.savefigの引数に bbox_inches='tight' をつけるとよい。
plt.savefig("output-scatter.pdf", transparent=True)

2021年3月27日 Seabornで作成したFigureのPDFでの保存方法も追記。下記のリンクを参考にした。
リンク3
Seaborn moduleは作成したfigの指定を,別個に行ってこれをPDFpagesで保存する必要がある。

例として

illustrator-editable-seaborn-figure.py
import matplotlib
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42

import seaborn as sns
from matplotlib.backends.backend_pdf import PdfPages
.............
.............
pp = PdfPages("Seaborn_Edittedfigure.pdf")

g = sns.catplot(x="Type", y="SNV", kind="violin", data=df)
pp.savefig(g.fig)
h = sns.catplot(x="Group", y="INDEL", kind="swarm", data=df)
pp.savefig(h.fig)
i = sns.catplot(x="Type", y="MNV", kind="box", data=df)
pp.savefig(i.fig)
pp.close()

の用に行うと,1つのPDFファイルの別々のベージにseabornで作成したFigureがイラストとして保存されていく。
最後にpp.close()を行わないと,作成したPDFが開けなくなるので注意する。

4
7
0

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
4
7