2.

棒グラフ

編集

これはMatplotlibの棒グラフに関する記事です。

縦棒グラフ横棒グラフの説明をします。

 

■縦棒グラフ

構文

bar(left, height)

 

import matplotlib.pyplot as plt

left = range(0, 3)
height = [10, 20, 30]
label = ["A", "B", "C"]

plt.bar(left, height, tick_label=label)

plt.show()

tick_labelを指定することで棒グラフにラベルを貼ることができます。

 

出力結果

 

 

■横棒グラフ

構文

barh(bottom, width)

 

import matplotlib.pyplot as plt

bottom = range(0, 3)
width = [10, 20, 30]
label = ["C", "B", "A"]

plt.barh(bottom, width, tick_label=label)

plt.show()

tick_labelを指定することで棒グラフにラベルを貼ることができます。

 

出力結果

 

編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. 線グラフ
  2. 棒グラフ
  3. 円グラフ
  4. 散布図
  5. タイトルと軸のラベル
  6. グリッド線