LoginSignup
2
0

More than 3 years have passed since last update.

[Jupyter][Python] matplotlib の hist で x軸の目盛と棒の中心線のずれを直す(1刻みでカウントする場合用)

Last updated at Posted at 2020-12-15

matplotlib.pyplothistでヒストグラムを描画した時、x軸の目盛と棒の中心線のずれをrangeを指定する事で直します。ただし下のコードは1刻みでカウントする場合のrangeです。

import pandas as pd
import matplotlib.pyplot as plt

s = pd.Series([1,2,2,4,4,4,4])
bins = (s.max()-s.min()+1)

# 何もしない場合
plt.hist(s, bins=bins)
plt.show()

# 修正した場合
plt.hist(s, bins=bins, range=(s.min()-.5, s.max()+.5))
plt.show()

スクリーンショット 2020-12-15 午前9.03.02.png

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