7
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でx軸がlogスケールのヒストグラムを描く [ほぼ自分用メモ]

Posted at
plot.py
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

# prepare data
r1=np.random.rand(100) * 1e3
r2=np.random.rand(100) * 1e6
df=np.r_[r1,r2]

# plot
ax=plt.figure(figsize=(5,5)).add_subplot(111)
ax.hist(x=df, bins=np.logspace(0, 10, 50), color='dodgerblue', alpha=0.75)
ax.set_xscale('log')
ax.set_xlabel('score')
ax.set_ylabel('num')
plt.savefig('plot_out.pdf')

出来上がりの図がこちら

plot_out_2.png

メモ

python3.6で実行可能を確認。

bins=np.logspace(0, 10, 50)
bins=10**np.linspace(0, 10, 50) と同じ。

bins=np.logspace(0, 10, 50) は 、10^0から10^10までを50個のbinに分ける。

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