LoginSignup
158
149

More than 5 years have passed since last update.

matplotlibのstyleを変える

Last updated at Posted at 2016-10-25

Matplotlibでかっこいいプロットにしたい

seabornのプロットはかっこいい。毎回インポートするのめんどくさいなと思っていたのですが、seabornをインポートせずにseabornのスタイルを使うことができることに気づいた。(もしかすると当たり前?)
もちろん、あらかじめseabornをインストールしておく必要はある。
どんなプロットができるか、メモ。

どんなスタイルがあるか確認

matplotlib/mpl-data/stylelibというフォルダに入っているxxx.mplstyleがスタイルファイル。もちろん自分で作ることもできる。結局、どのスタイルも一長一短なので、自分で作って置いておくのが一番いいかもね。

中身の例:dark_background.mplstyle


 Set black background default line colors to white.

lines.color: white
patch.edgecolor: white

text.color: white

axes.facecolor: black
axes.edgecolor: white
axes.labelcolor: white
axes.prop_cycle: cycler('color', ['8dd3c7', 'feffb3', 'bfbbd9', 'fa8174', '81b1d2', 'fdb462', 'b3de69', 'bc82bd', 'ccebc4', 'ffed6f'])

xtick.color: white
ytick.color: white

grid.color: white

figure.facecolor: black
figure.edgecolor: black

savefig.facecolor: black
savefig.edgecolor: black

ベースにしたいスタイルを選んで、自分でちょこちょこいじるのが良さそう。

Examples

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def testplot():
    x=np.arange(21)
    for i in range(2,9):
        y=i*0.3*np.sin(np.pi/10*x)
        plt.plot(x,y,'o-',label=str(i-1))

    plt.legend()
    plt.show()

####ここにしたの呪文を入れるplt.style.use()####
testplot()

デフォルト

何も呪文を唱えない時。
image

plt.style.use('default')

なぜかデフォルトと違い、困惑。そして、plt.style.use('classic')と同じ結果。

image

plt.style.use('bmh')

image

plt.style.use('dark_background')

image

plt.style.use('fivethirtyeight')

image

plt.style.use('ggplot')

image

plt.style.use('grayscale')

ここまでがおそらくもともとmatplotlibに入ってるスタイル。
image

plt.style.use('seaborn-bright')

image

plt.style.use('seaborn-colorblind')

image

plt.style.use('seaborn-dark')

image

plt.style.use('seaborn-dark-palette')

image

plt.style.use('seaborn-darkgrid')

image

plt.style.use('seaborn-deep')

image

plt.style.use('seaborn-muted')

image

plt.style.use('seaborn-pastel')

image

plt.style.use('seaborn-ticks')

tickが外向きになりました。
image

plt.style.use('seaborn-white')

そしてなくなりました。
image

plt.style.use('seaborn-whitegrid')

image

組み合わせて使うことも!

plt.style.use('seaborn-colorblind')
plt.style.use('seaborn-whitegrid')

image

サイズ変更系のスタイル

枠の線がなくなっていますね。こちらの方が好み。
そして、サイズに合わせて文字なども大きくなるので、解像度を上げたい時には便利そうです。
サイズを変更したい場合には、サイズ変更系のスタイルを最初に宣言するのが良さそうです。
seaborn-paper<seaborn-notebook<seaborn-talk<seaborn-poster
image
image
image
image

最後に

ほかのオススメスタイルもあれば是非教えてください!

158
149
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
158
149