8
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Pandasを用いて複数のグラフを描く

Posted at

#Pandasを用いて複数のグラフを描く
1つの領域に複数のグラフを描く方法についてです. 例えば, こちらの記事ですとpandasに加えてmatplotlibをimportして描画をしていますが, 今回はpandasのライブラリのみを用いて描画する方法について書きます.

以下のように,ax1に1つ目のグラフの描画情報を代入し, 2つ目のグラフのplotの引数のaxに1つ目のグラフ情報であるax1を代入することで実現できるようだ. こうすることで, matplotlibを使わずに簡潔に記述することができる.


import pandas as pd
import numpy as np

#データフレームの作成.
df = pd.DataFrame(np.arange(12).reshape(4, 3),
                  columns=["colA", "colB", "colC"],
                  index=["row1", "row2", "row3", "row4"])

#1つ目のグラフ.
ax1 = df.plot(x="colA", y="colB")
#2つ目のグラフ.
df.plot(x="colA", y="colC", ax = ax1)

そして, 出力結果は以下である.

screenshot.png

#参考文献
https://stackoverflow.com/questions/42128467/matplotlib-plot-multiple-columns-of-pandas-data-frame-on-the-bar-chart/42131286

8
6
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
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?