histogram: Fix bug with the -N normal curve for reverse cumulative histograms (-Qr) - #9218
Merged
Merged
Conversation
Two separate mistakes made the -N overlay unusable together with -Qr, while -Q was fine: - pshistogram_plot_boxes derived "area" (the grand total, used to scale the -N curve) by picking up the last bin, on the grounds that it "has the entire sum". That holds for -Q, where the bars count up, but under -Qr they count down and the last bin is ~0. On a 6521-point sample the reported area came out as 21 instead of 6521, so the curve was drawn roughly 300x too small -- flat against the axis. With -S (stairs) the last bin is exactly 0, so the curve vanished altogether. Use F->sum_w, which is the same value the last bin gives under -Q and is correct either way, and hoist it out of the bar loop since it no longer depends on the bin. - The reverse curve was computed as f - yp, but f is only half the grand total (it is set to 0.5 and later multiplied by area), while the forward curve yp spans 0 to 2f. Subtracting f therefore started the curve at half height and drove it negative past the mean instead of running from the total down to zero. Use 2f - yp. With both fixed, the -Qr curve is the mirror image of the -Q one and tracks the bars, for every -Z mode and not just counts. Adds a test asserting that the reported area equals the number of input points for both -Q and -Qr; it fails on the previous code for -Qr. No baseline image changes: no existing test plots -Qr, and the -Q value is unchanged, so all eight pshistogram baselines still compare at RMS 0.0000, including distributions.sh which combines -Q with -N. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fails:
gmt histogram @v3206_06.txt -T-7000/0/250 -Z0 -JX12c/8c -Baf -Ggray -W0.5p -N0+p2p,red -Qr -png lixoOutput with bug:
Output with this fix:
Done with Claude Sonnet 5 and review by Opus 5.
This PR also adds a test asserting that the reported area equals the number of input points for both -Q and -Qr; it fails on the previous code for -Qr.