Skip to content
Draft
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
8 changes: 8 additions & 0 deletions doc/api/colorbar_multivariate_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
***************************************
``matplotlib.colorbar_multivariate``
***************************************

.. automodule:: matplotlib.colorbar_multivariate
:members:
:undoc-members:
:show-inheritance:
4 changes: 4 additions & 0 deletions doc/api/figure_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Annotating
:nosignatures:

Figure.colorbar
Figure.colorbar_bivar
Figure.colorbar_multivar
Figure.legend
Figure.text
Figure.suptitle
Expand Down Expand Up @@ -254,6 +256,8 @@ Annotating
:nosignatures:

SubFigure.colorbar
SubFigure.colorbar_bivar
SubFigure.colorbar_multivar
SubFigure.legend
SubFigure.text
SubFigure.suptitle
Expand Down
1 change: 1 addition & 0 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Alphabetical list of modules:
cm_api.rst
collections_api.rst
colorbar_api.rst
colorbar_multivariate_api.rst
colorizer_api.rst
colors_api.rst
container_api.rst
Expand Down
2 changes: 2 additions & 0 deletions doc/api/pyplot_summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Colormapping

clim
colorbar
colorbar_bivar
colorbar_multivar
gci
sci
get_cmap
Expand Down
23 changes: 23 additions & 0 deletions doc/release/next_whats_new/colorbar_bivar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Colorbars for bivariate colormaps
---------------------------------

The new method `.Figure.colorbar_bivar` (and `.pyplot.colorbar_bivar`) adds a
colorbar for an image that uses a bivariate colormap. The colormap is shown as a
2D image, with the first data variable along the y-axis and the second along the
x-axis.

.. plot::
:include-source: true
:alt: An image colored with a bivariate colormap and a square colorbar on its right.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, x)

fig, ax = plt.subplots()
im = ax.imshow((np.sin(X), np.cos(Y)), cmap='BiOrangeBlue')
cbar = fig.colorbar_bivar(im, fraction=0.3)
cbar.set_ylabel('sin(x)')
cbar.set_xlabel('cos(y)')
22 changes: 22 additions & 0 deletions doc/release/next_whats_new/colorbar_multivar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Colorbars for multivariate colormaps
------------------------------------

The new method `.Figure.colorbar_multivar` (and `.pyplot.colorbar_multivar`)
adds one colorbar per variable for an image that uses a multivariate colormap.
The colorbars can be arranged in several rows or columns with *n_major*.

.. plot::
:include-source: true
:alt: An image colored with a three-variable colormap and three colorbars on its right.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-3, 3, 100)
X, Y = np.meshgrid(x, x)

fig, ax = plt.subplots()
im = ax.imshow((np.sin(X), np.cos(Y), np.sin(X + Y)), cmap='3VarAddA')
cbars = fig.colorbar_multivar(im)
for cbar, label in zip(cbars, ['sin(x)', 'cos(y)', 'sin(x + y)']):
cbar.set_label(label)
3 changes: 2 additions & 1 deletion lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,8 @@ def press_zoom(self, event):
# to the edge of the Axes bbox in the other dimension. To do that we
# store the orientation of the colorbar for later.
parent_ax = axes[0]
if hasattr(parent_ax, "_colorbar"):
if hasattr(parent_ax, "_colorbar") and hasattr(parent_ax._colorbar,
"orientation"):
cbar = parent_ax._colorbar.orientation
else:
cbar = None
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,8 @@ def remove(self):

try:
ax = self.mappable.axes
if ax is None:
return
except AttributeError:
return
try:
Expand Down
Loading
Loading