- double range;
-
- gsl_histogram_get_range (h->gsl_hist, 0, &x_min, ¬_used);
- range = not_used - x_min;
- gsl_histogram_get_range (h->gsl_hist, bins - 1, ¬_used, &x_max);
-
- abscissa_scale = (geom->data_right - geom->data_left) / (x_max - x_min);
- ordinate_scale = (geom->data_top - geom->data_bottom) /
- gsl_histogram_max_val (h->gsl_hist);
-
- cairo_move_to (cr, geom->data_left, geom->data_bottom);
- for (d = geom->data_left;
- d <= geom->data_right;
- d += (geom->data_right - geom->data_left) / 100.0)
+ double binwidth;
+ double x;
+
+ gsl_histogram_get_range (h->gsl_hist, 0, &x_min, &x_max);
+ binwidth = x_max - x_min;
+
+ /* The integral over the histogram is binwidth * sum(bin_i), while the integral over the pdf is 1 */
+ /* Therefore the pdf has to be scaled accordingly such that the integrals are equal */
+ ordinate_scale = binwidth * gsl_histogram_sum(h->gsl_hist);
+
+ /* Clip normal curve to the rectangle formed by the axes. */
+ cairo_save (cr);
+ cairo_rectangle (cr, geom->axis[SCALE_ABSCISSA].data_min, geom->axis[SCALE_ORDINATE].data_min,
+ geom->axis[SCALE_ABSCISSA].data_max - geom->axis[SCALE_ABSCISSA].data_min,
+ geom->axis[SCALE_ORDINATE].data_max - geom->axis[SCALE_ORDINATE].data_min);
+ cairo_clip (cr);
+
+ cairo_move_to (cr, geom->axis[SCALE_ABSCISSA].data_min, geom->axis[SCALE_ORDINATE].data_min);
+ for (x = geom->axis[SCALE_ABSCISSA].min;
+ x <= geom->axis[SCALE_ABSCISSA].max;
+ x += (geom->axis[SCALE_ABSCISSA].max - geom->axis[SCALE_ABSCISSA].min) / 100.0)