Repository navigation
Bivar colorbar - #32606
Bivar colorbar#32606trygvrad wants to merge 4 commits into
Conversation
- Colorizer: an existing MultiNorm passed as *norm* is used as is instead of being wrapped in a new MultiNorm, which raised a ValueError. - MultiNorm.autoscale_None only emits the 'changed' signal when the limits of a constituent norm actually changed. - Colorbar.remove no longer fails when the mappable has no Axes. Changes implemented with the assistance of AI and manually evaluated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| fig = ( # Figure of first Axes; logic copied from make_axes. | ||
| [*ax.flat] if isinstance(ax, np.ndarray) | ||
| else [*ax] if np.iterable(ax) | ||
| else [ax])[0].get_figure(root=False) |
There was a problem hiding this comment.
Let's factor this our into a helper colorbar._figure_of_first_axes() so that we can write
| fig = ( # Figure of first Axes; logic copied from make_axes. | |
| [*ax.flat] if isinstance(ax, np.ndarray) | |
| else [*ax] if np.iterable(ax) | |
| else [ax])[0].get_figure(root=False) | |
| fig = colorbar._figure_of_first_axes(ax) |
Reuse is a secondary benefit. More important is abstracting the logical details away and giving the concept a clear name to reduce complexity here.
There was a problem hiding this comment.
On a more general note, this colorbar_bivar has a lot of code overlap with colorbar. That hints towards a common underlying concept. Could we extract that, give it a name and reuse it for both functions?
| The mappable whose colormap and norm will be used. | ||
|
|
||
| location : None or {'left', 'right', 'top', 'bottom'} | ||
| Set the bivariate colorbars's location |
There was a problem hiding this comment.
| Set the bivariate colorbars's location | |
| The location of the bivariate colorbar relative to the Axes. | |
| If not None, this information is used to determaine | |
| 'auto' *ticklocations*. |
| location=None, | ||
| ticklocations=('auto', 'auto'), | ||
| aspect=1.0, | ||
| ): |
| def update_normals(self, mappable=None): | ||
| """Redraw the colorbar after the norm or colormap of the mappable changed.""" | ||
| self._draw_all() |
There was a problem hiding this comment.
Do we still need this, when it delegates everything to _draw_all? Possibly yes, to satisfy the signature, and maybe for symmetry with Colorbar? A brief comment on this would be helpful.
Yes, I think that's a good idea. I would put everyting in as provisional so that we can still reconsider when we see that a different organization is better. We could also consider then to rename |
|
Overall thanks a lot for splitting. This is so much easier to review 🎉 |
Add `Figure.colorbar_bivar` and `pyplot.colorbar_bivar`, which draw the colorbar of a bivariate colormap as a 2D image, with one data variable along each axis. The new `BivarColorbar` class lives in the new module `matplotlib.colorbar_bivar`. Its Axes is created by the existing `colorbar.make_axes` / `colorbar.make_axes_gridspec`, so it takes part in layout (including constrained layout) like a regular colorbar, and `colorbar.py` itself is not changed. Changes implemented with the assistance of AI and manually evaluated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
00ebc6f to
7ee66e1
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This PR has a long history. It is part of Bivariate and Multivariate Colormapping and contains changes that were previously part of #31214 which is being separated into multiple parts with the use of AI. This is part 2 of 4 and Depends on #32605. Only the last commit ("Add bivariate colorbars") is new in this PR.
PR summary
Figure.colorbar_bivar/SubFigure.colorbar_bivarandpyplot.colorbar_bivar.matplotlib.colorbar_multivariatewithBivarColorbar,make_bivar_axes,make_bivar_axes_gridspec.colorbar.pyis not changed (see discussion in Multivar colorbar #31214). The colorbar Axes is created by the existingcolorbar.make_axes/make_axes_gridspec(with aspect=1 and no orientation), so placement, gridspec and constrained layout behave as for a normal colorbar.set_xlabel/set_ylabel,xaxis/yaxis,update_normals, remove. No alpha.BivarColorbarcompensates).Figure.colorbarnow raises a clear error when given a bivariate colormap, pointing tocolorbar_bivar.ax._colorbarhas an orientation (backend_bases.py).set_ylabel).test_colorbar_multivariate.py; baseline images moved from Multivar colorbar #31214 unchanged.doc/release/next_whats_new/colorbar_bivar.rst; new API pagecolorbar_multivariate_api.rst.There is no example in the docs yet, that will come in a separate PR.
Here is an example:
AI Disclosure
The split of #31214 into smaller PRs, and the changes requested in review there, were
made with the assistance of an AI coding assistant (Claude). All changes were reviewed
and tested by me.
PR quality check