はじめに
matplotlibではグラフの見た目をplt.style.use(‘###’)のようにスタイルを適用することで容易に変えることができる。どのようなものがあるかについては下記記事で解説した。

[matplotlib] 1. plotの見た目を変えるスタイルの設定
matplotlibでplotの見た目を変えるスタイルの設定について解説する。
このスタイルについては、自分だけのオリジナルスタイルを作ることもできる。ここではExcelに似たスタイルを作成して適用することで、Excelのような図を表示する方法について説明する。
コード

解説
configフォルダの場所の確認
matplotlib.get_configdir()でconfigフォルダの場所を確認できる。隠しフォルダなので表示されない場合は、OSの設定で表示するようにする必要がある。
.configフォルダのmatplotlibフォルダにstylelibフォルダを作成して、stylelibフォルダにスタイルのファイル(.mplstyle)を入れる。
styleの作成
フォントの大きさ、軸、凡例などの設定を下記のように記述して、stylelibフォルダに入れる。
このファイルは下記ボタンからダウンロードできる。
コードをダウンロード(.mplstyleファイル)styleの適用
ファイル名をexcel.mplstyleとしているので、plt.style.use(‘excel’)で設定が適用される。
図の表示
下図のように、Excelのような図が表示される。

参考
https://matplotlib.org/tutorials/introductory/customizing.html?highlight=style%20sheets#customizing-matplotlib-with-style-sheets-and-rcparams
https://matplotlib.org/tutorials/introductory/customizing.html?highlight=style%20sheets#the-matplotlibrc-file
コメント