3
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 5 years have passed since last update.

Matplotlib で軸をパーセント (%) 表示にする

Posted at

たいしたことない話だけど忘れがちなので。

サンプルデータ

import numpy as np

arr = np.random.randn(10)
print(arr)
# => array([ 0.24671671, -0.8013258 , -0.29147271, -0.10755521, -1.39065478,
#           -1.03983494, -0.75304377,  0.62645801,  0.76417769, -0.31104797])

普通にプロットした場合

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.bar(x=range(len(arr)), height=arr)
ax.set_title('何らかの割合')

image.png

これだと割合であることがわかりにくい。

パーセント表示する場合

import matplotlib
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.bar(x=range(len(arr)), height=arr)
ax.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter(1.0))
ax.set_title('何らかの割合')

image.png

matplotlib.ticker — Matplotlib documentation

3
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
3
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?