Displaying a histogram of logarithmically distributed data (in this example, random lognormal noise) is easy to do in matplotlib:
import numpy as np
import matplotlib.pyplot as plt
logx = np.log10(x)
bins = 10**np.linspace(min(logx), max(logx), 101)
plt.hist(x, bins=bins)
plt.xscale('log')
However, when I try to normalise this distribution by adding density=True to plt.hist, it distorts the distribution due to the different bin widths.
How can I make a plot which is a normalised PDF of log(x), where the data distribution and horizontal axis ticks are exactly as they are in the first figure?



