To arrange data in bins then display them with equal width bars you can use matplotlib
in Python
The previous Python answer doesn't bin the values, set them at equal distance nor handle (-infinity, 0.9) bin
The code here hopefully does:
import matplotlib.pyplot as plt
import numpy as np
# data and bins
d = [-0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -
0.2, -0.1, 0, 0.1, 0.5, 1, 1.5, 2, 2.5, 4]
bin_boundaries = [-0.9, -0.8, -0.7, -0.6, -0.5, -0.4,
-0.3, -0.2, -0.1, 0, 0.1, 0.5, 1, 1.5, 2, 2.5, 4]
# Account for (-inf, min(d)) bin
added_inf = False
min_d = min(d)
if min_d < bin_boundaries[0]:
bin_boundaries.insert(0, min_d)
added_inf = True
# Bin data
fig, ax = plt.subplots()
counts, bins, _ = ax.hist(d, bins=bin_boundaries)
plt.close()
# Generate tick labels and handle (-inf, min(d)) bin
bins_str = [f"{bins[i]} to {bins[i+1]}" for i in range(len(bins) - 1)]
if added_inf:
bins_str[0] = f"-inf to {bins[1]}"
else:
bins = np.insert(bins, 0, [bins[0] - 1])
counts = np.insert(counts, 0, [0])
bins_str.insert(0, f"-inf to {bins[1]}")
fig, ax = plt.subplots()
# Ajdust size of plot
fig.set_dpi(150)
# Draw graph with bins_str as labels
ax.bar(bins_str, counts, width=1.0)
# Make labels vertical
plt.xticks(rotation=90, ha='center')
plt.show()
plt.close()