LoginSignup
10
12

More than 5 years have passed since last update.

pythonでx軸がlogスケールのヒストグラムを書く

Posted at

X軸がlogスケールのグラフをpythonで書くメモ

import pylab as pl
import numpy as np

二つの山を持つ分布の作成

data1 = (np.random.normal(size=100) + 10)* 1e-5
data2 = (np.random.normal(size=100) + 10)* 1e-10
data = np.r_[data1, data2]
#ヒストグラムの作成
print(data)
pl.hist(data)

Unknown-6.png

xをlogスケールにするだけではダメ

pl.hist(data)
pl.gca().set_xscale("log")

Unknown.png

それぞれの棒(binsとも言う)の幅が対数じゃないのね、なるほど

#ヒストグラムの作成
print(data)
pl.hist(data, bins=np.logspace(-11, -3, 500))
pl.gca().set_xscale("log")

Unknown2.png

いけた。np.logspaceのオプションは「10^-11から10^3の範囲で500個のbinを作ってね」っていう感じ。

10
12
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
10
12