LoginSignup
8
14

More than 5 years have passed since last update.

pandasで複数ラインプロットするときのTips

Last updated at Posted at 2017-08-31

はじめに

毎回調べるので。

subplots=True のときにax配列渡すとよしなにサブプロットしてくれるのと、 cmap 指定でラインごとに色変えるとかはあんまり情報出てこないので、誰かの役に立つかも。

よくつかうやつ

import matplotlib.pyplot as plt
from matplotlib import cm

_, ax = plt.subplots(2,1, figsize=(16, 8))
df.plot(
    grid=True, # グリッドつける
    style='-', # ラインスタイルの指定
    cmap=cm.tab20, # ラインのcolormapを変更
    subplots=True, # ラインごとにsubplotを分ける
    ax=axes, # カラム数とlen(axes)があっていれば、よしなにサブプロットしてくれる
)
plt.show()

カラーマップ

追記

  • cm.tab20 の代わりに cm.get_cmap("tab20") が使える。
  • plt.plot 等のcolorでは cm.tab20.colors[n] が使える。
8
14
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
8
14