Add TestForIssue481 demo - multiple histogram x-axis alignment#969
Merged
Conversation
Documents the correct usage of Histogram(data, numBins, min, max) with a shared global range when combining multiple histograms on one chart. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Issue #481 reported that combining two
Histograminstances with non-overlapping data ranges onto the sameCategoryChartproduces an incorrect x-axis. This is not a bug in the library - it is a usage pattern that requires explicit configuration.Root cause:
Histogram(data, numBins)auto-detects its ownmin/maxfrom its data. When two histograms have different ranges they generate disjoint bin-center lists, andCategoryChart(which uses x-axis values as categorical labels) cannot reconcile them automatically.Fix / correct usage: supply the same shared global
[min, max]to everyHistogramusing the explicit-range constructor:Note: to get bin centers at exact integer values, extend the range by half a bin on each side of the data extent (
binSize = 1-> extend by 0.5, giving[-2.5, 2.5]for data spanning[-2, 2]).TestForIssue481.javaopens two charts side-by-side: one reproducing the broken behavior and one showing the correct shared-range approach. Issue #481 has been closed with this explanation.