From 3a7f9a9d4114d698538dc38fa8e8e95464fbbb34 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Tue, 30 Jan 2024 18:27:00 +0100 Subject: [PATCH] update bin size depending on bin width --- squiggle_more.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/squiggle_more.c b/squiggle_more.c index eceb37e..247cb74 100644 --- a/squiggle_more.c +++ b/squiggle_more.c @@ -275,7 +275,19 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) { for (int i = 0; i < n_bins; i++) { double bin_start = min_value + i * bin_width; double bin_end = bin_start + bin_width; - printf(" [%4.1f, %4.1f): ", bin_start, bin_end); + if(bin_width < 0.01){ + printf(" [%4.3f, %4.3f): ", bin_start, bin_end); + } else if(bin_width < 0.1){ + printf(" [%4.2f, %4.2f): ", bin_start, bin_end); + } else if(bin_width < 1){ + printf(" [%4.1f, %4.1f): ", bin_start, bin_end); + } else if(bin_width < 10){ + printf(" [%4.0f, %4.0f): ", bin_start, bin_end); + } else { + printf(" [%4f, %4f): ", bin_start, bin_end); + } + // number of decimals could depend on the number of bins + // or on the size of the smallest bucket int marks = (int)(bins[i] * scale); for (int j = 0; j < marks; j++) {