Python Pandas Histogram Log Scale

I'd recommend using the log=True parameter in the pyplot hist function:

Setup step

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt  

df = pd.DataFrame({'column_name': np.random.normal(size=2000)})

Using pyplot:

plt.hist(df['column_name'], log=True)

enter image description here

Or equivalently, you could use the plot method of the dataframe column (series) directly:

df["column_name"].plot(kind="hist", logy=True)

There's also logx for log scaling the x-axis and loglog=True for log scaling both axes.


Hard to diagnose without any data. The following works for me:

import numpy as np
import matplotlib.pyplot as plt
import pandas
series = pandas.Series(np.random.normal(size=2000))
fig, ax = plt.subplots()
series.hist(ax=ax, bins=100, bottom=0.1)
ax.set_yscale('log')

enter image description here

The key here is that you pass ax to the histogram function and you specify the bottom since there is no zero value on a log scale.