Skip to content

Sync histograms with the updated tutorial - #856

Merged
martin-martin merged 2 commits into
masterfrom
maintenance/python-histograms-20260920
Oct 12, 2026
Merged

martin-martin merged 2 commits into
masterfrom
maintenance/python-histograms-20260920

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Companion code sync for the maintenance update of Python Histogram Plotting: NumPy, Matplotlib, pandas & Seaborn.

What changed

  • seaborn.distplot() is gone. It is removed in seaborn v0.14, so the two calls move to the supported API: sns.histplot(d, kde=True) for the KDE figure, and an explicit stats.laplace.fit() plus a histplot(..., stat="density") overlay for the distribution-fitting figure (histplot() has no fit= argument). The warnings.catch_warnings() wrapper existed only to silence a distplot()/normed warning, so it and the now-unused warnings import are dropped.
  • NumPy 2 scalars. max(a) becomes np.max(a), and the reproduced collections.Counter dict calls .tolist() on both sides so it prints {0: 1, 1: 3, ...} instead of {np.int64(0): np.int64(1), ...} — matching the article's output block.
  • New histograms/requirements.txt, pinned to the same versions as the article's dependencies field (plus scipy, which the script imports).

Verification

  • Fresh venv on Python 3.14 from the new requirements.txt; MPLBACKEND=Agg python histograms.py runs to completion (exit 0), every assert passes, and the printed value_counts() / pd.cut() tables match the article's updated output blocks byte for byte.
  • uvx ruff@0.14.1 format --check histograms -> 1 file already formatted.
  • uvx ruff@0.14.1 check histograms -> All checks passed!

🤖 Generated with Claude Code

@martin-martin
martin-martin merged commit b87f2ca into master Oct 12, 2026
1 check passed
@martin-martin
martin-martin deleted the maintenance/python-histograms-20260920 branch October 12, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants