From c01407d33357128bbb0cc742509312408f2abece Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 13 Jan 2019 12:29:18 +0100 Subject: [PATCH] Document how to make colorbars "without" a ScalarMappable. (Intentionally made the reference to ScalarMappable a fully qualified one (removing the `~`), as it's probably a slightly obscure class...) --- lib/matplotlib/colorbar.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index aac6179292ed..74634fb4c9a4 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -141,12 +141,17 @@ Parameters ---------- mappable - The `~matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.Image`, - `~matplotlib.contour.ContourSet`, etc.) to which the colorbar applies. + The `matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.Image`, + `~matplotlib.contour.ContourSet`, etc.) described by this colorbar. This argument is mandatory for the `.Figure.colorbar` method but optional for the `.pyplot.colorbar` function, which sets the default to the current image. + Note that one can create a `ScalarMappable` "on-the-fly" to generate + colorbars not attached to a previously drawn artist, e.g. :: + + fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap, ax=ax)) + cax : :class:`~matplotlib.axes.Axes` object, optional Axes into which the colorbar will be drawn.