Skip to content

fix(matplotlib): corriger le rendu des histogrammes adaptatifs - #35

Open
ElouenGinat wants to merge 11 commits into
mainfrom
fix/matplotlib-hist-regressions-34
Open

ElouenGinat wants to merge 11 commits into
mainfrom
fix/matplotlib-hist-regressions-34

Conversation

@ElouenGinat

@ElouenGinat ElouenGinat commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

What

  • Preserve Khiops frequencies and keep narrow adaptive bins visible.
  • Reject unsupported histtype="barstacked".
  • Export hist from the package root and infer its return type from histtype.
  • Simplify the demo, use root-level imports, and refresh its figures.

Validation

  • uv run pytest -q
  • Demo notebook executed end to end
  • uv run sphinx-build -W --keep-going -b html docs docs/_build/html
  • Pre-commit hooks

Closes #34

Réutiliser les fréquences Khiops pour les valeurs extrêmes et rendre visibles les classes très étroites par défaut. Refuser également le type barstacked non pris en charge.

Closes #34
@ElouenGinat ElouenGinat linked an issue Sep 22, 2026 that may be closed by this pull request
@github-actions

github-actions Bot commented Sep 22, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

🚀 View preview at
https://KhiopsML.github.io/khisto-python/pr-preview/pr-35/

Built to branch gh-pages at 2026-09-22 14:32 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@ElouenGinat
ElouenGinat requested review from marcboulle and popescu-v and a lite review from Copilot and removed request for marcboulle September 22, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The cumulative density implementation, ec edge styling, and stale notebook import remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
What changed in this PR

Updates the Matplotlib histogram adapter to preserve Khiops frequencies, improve adaptive-bin rendering, and expose hist at the package root.

Changes:

  • Adds typed histogram returns and rejects unsupported stacked histograms.
  • Updates plotting behavior, tests, documentation, CI, changelog, and demo metadata.
File Summary
tests/​plot/​test_matplotlib_histogram.py Adds histogram behavior and typing tests.
src/​khisto/​matplotlib/​hist.py Implements frequency-backed plotting and return handling; cumulative density behavior and ec styling require changes.
src/​khisto/​__init__.py Exports hist at the package root.
sandbox/​khisto_demo.ipynb Updates demo metadata; retains a stale _hist import that causes an import error.
pyproject.toml Adds the Python 3.10 typing dependency.
docs/​index.rst Updates usage examples.
docs/​conf.py Configures Matplotlib API documentation.
docs/​api_comparison.md Documents unsupported histogram options.
CHANGELOG.md Records the histogram changes.
.github/​workflows/​ci.yaml Adds optional-dependency installation coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/khisto/matplotlib/hist.py Outdated
Comment thread src/khisto/matplotlib/hist.py Outdated
ElouenGinat and others added 2 commits September 22, 2026 16:20
…ct for unequal-width bins'

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

@marcboulle marcboulle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai bien aimé la simplification de la démo ;)

Pour le reste, je n'ai fait que survolé le code rapidement. Je ne comprend pas tous les détails et le pourquoi des évolutions. C'est suite aux retours utilisateurs? ou à des tests approfondis?

J'ai quelques remarques et surtout des questions de détail.

Comment thread docs/demo.ipynb

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le rendu de khisto.histogram est un peu bizarre sur un navigateur:

Image

Passer à plus simplement khisto.histogram ?

Comment thread docs/demo.ipynb
"\n",
"> 📚 Go further with [Histograms - Khiops](https://khiops.org/learn/histograms/),\n",
"a didactic walk-through from the simplest histogram to the most complex."
"Khisto uses the **Khiops optimal binning algorithm** to choose both the number and\n",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L'introduction est meilleure qu'avant ;)

Comment thread src/khisto/matplotlib/hist.py Outdated
values, edges, patches = ax.hist(
bin_edges[:-1].tolist(),
bin_edges.tolist(),
weights=frequencies.tolist(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solution alternative au précédent np.nextafter, plus simple et plus robuste?

if histtype == "bar" and "edgecolor" not in kwargs:
if not isinstance(histogram_patches, BarContainer):
raise TypeError("Matplotlib unexpectedly returned non-bar patches.")
for patch in histogram_patches.patches:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selon ma compréhension, tu forces un edgecolor de même couleur que facecolor si ce paramètre n'est pas utilisé, pour forcer un épaisseur minimale aux bins:

  • mais comment-est pris en compte alors que c'est fait après l'appel à ax.hist?
  • quid si on a mis paramétré linewidth à 0? (pas de problème après tout?)
  • quid si on a mis paramétré edgecolor à blanc? (on ne verra pas le bin, qui restera d'épaisseur nulle?)

Davantage commenter le code: sans le contexte, on ne comprend pas l'intention.

This branch has not been deployed

No deployments
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.

Fix invisible narrow bins and incorrect extreme-value counts

3 participants