Brian Brian - 1 year ago 202
Python Question

How to have logarithmic bins in a Python histogram

As far as I know the option Log=True in the histogram function only refers to the y-axis.


I need the bins to be equally spaced in log10. Is there something that can do this?

Answer Source

use logspace() to create a geometric sequence, and pass it to bins parameter. And set the scale of xaxis to log scale.

import pylab as pl
import numpy as np

data = np.random.normal(size=10000)
pl.hist(data, bins=np.logspace(0.1, 1.0, 50))

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download