Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Overlay 2 histograms to compare them
def overlaid_histogram(data1, data2, n_bins = 0, data1_name="", data1_color="#539caf", data2_name="", data2_color="#7663b0", x_label="", y_label="", title=""):
# Set the bounds for the bins so that the two distributions are fairly compared
max_nbins = 10
data_range = [min(min(data1), min(data2)), max(max(data1), max(data2))]
binwidth = (data_range[1] - data_range[0]) / max_nbins
if n_bins == 0
bins = np.arange(data_range[0], data_range[1] + binwidth, binwidth)
bins = n_bins
# Create the plot
_, ax = plt.subplots()
ax.hist(data1, bins = bins, color = data1_color, alpha = 1, label = data1_name)
ax.hist(data2, bins = bins, color = data2_color, alpha = 0.75, label = data2_name)
ax.legend(loc = 'best')
Copy link

scipliccodes commented Apr 4, 2018

it seams there is a problem with the code in line 9. I gues there is a missing colon at the end of the line:

if n_bins == 0:
instead of
if n_bins == 0

Best regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment