def my_formatter(x, pos):
    """Format 1 as 1, 0 as 0, and all values whose absolute values is between
    0 and 1 without the leading "0." (e.g., 0.7 is formatted as .7 and -0.4 is
    formatted as -.4)."""
val_str = '{:g}'.format(x)
if np.abs(x) > 0 and np.abs(x) < 1:
    return val_str.replace('0', '', 1)
else:
    return val_str
np.random.seed(1)
vals = np.random.rand(1000)
major_formatter = FuncFormatter(my_formatter)
plt.hist(vals, bins=100)
ax = plt.subplot(111)
ax.xaxis.set_major_formatter(major_formatter)
plt.show()
removing leading 0 from matplotlib tick label formatting