LoginSignup
19
11

More than 5 years have passed since last update.

軸ラベルの数値を三桁カンマ区切りで描画する(matplotlib)

Last updated at Posted at 2018-12-17

matplotlibでグラフを描画する際、
y軸の数値を三桁毎にカンマで区切って表示したい場合があります。
検索してもすぐに見つからなかったので、備忘も含めて下記に記載。
Figure_1.png

import numpy as np
import matplotlib.pyplot as plt

height = np.array([1000, 2000, 3000, 4000, 5000])


fig, ax = plt.subplots(1, 1)
# 三桁カンマの設定
ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda x, loc: "{:,}".format(int(x))))

plt.bar(range(len(height)), height)
plt.show()

x軸を三桁区切りにする場合は、yaxisxaxisでOK

19
11
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
19
11