0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Python】pandasのplot.barメソッドでのグラフ表示

Posted at

pandasには折れ線グラフのplotメソッドや、ヒストグラムのplot.histメソッドなど、グラフを描画するメソッドがあります。

棒グラフはplot.barメソッドで描画しています。

df = pd.DataFrame(
np.random.rand(3, 3),
index=['one', 'two', 'three'],
columns=['A', 'B', 'C'])
df.plot.bar()
image.png
DataFrameのインデックスがx軸に、カラムが凡例になります。

このように複数の棒グラフを横に並べて表示する場合、Matplotlibのbarメソッドは棒の幅を指定してずらす必要がありますが、pandasのplot.barメソッドは自動調整してくれます。

また、積み上げ棒グラフも、Matplotlibは合計値を計算して描画する必要がありますが、pandasは「stacked=True」の引数を付けるだけです。

df = pd.DataFrame(
np.random.rand(3, 3),
index=['one', 'two', 'three'],
columns=['A', 'B', 'C'])
df.plot.barh(stacked=True)

image.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?