Apply unit conversion to hist2d's x/y/range, fixing datetime input by AdityaJagtap18 · Pull Request #32309 · matplotlib/matplotlib · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/behavior/hist2d_unit_conversion.rst
12 changes: 12 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7992,8 +7992,20 @@ def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
Previously, `~.Axes.hist2d` would force the axes limits to match the
extents of the histogram; now, autoscaling also takes other plot
elements into account.

.. versionchanged:: 3.12
*x* and *y* (and *range*, if given) are now passed through the axes'
unit converters before binning, so e.g. datetime inputs are handled
the same way as in `~.Axes.plot` and `~.Axes.scatter`. Previously
they were passed unconverted to `numpy.histogram2d`.
"""

x, y = self._process_unit_info([("x", x), ("y", y)], kwargs)
if range is not None:
(xmin, xmax), (ymin, ymax) = range
range = (self.convert_xunits((xmin, xmax)),
self.convert_yunits((ymin, ymax)))

h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
density=density, weights=weights)

Expand Down
40 changes: 40 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Loading