Bug fixed. In line 18 a function was returned instead of the array itself.
Bug fixed. new_values.append works in-place, therefore values was changed with it, having the same identity. A deepcopy of values prevents this from happening.
Bug fixed. The integral was taken along the y-axis instead of the x-axis. Just had to change x and y in trapz(x, y) to trapz(y, x).
Bug fixed in example_4.py. Interval from which the median was taken was too big. Changed it to a width of 1.2 instead of 5. Own comments in other files were deleted.
New diagram for the new width. It now follows the blue points much closer.
Own comments were deleted.