Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cbd04c

Browse files
anntzertimhoffm
authored andcommitted
Document how to make colorbars "without" a ScalarMappable. (#13171)
(Intentionally made the reference to ScalarMappable a fully qualified one (removing the `~`), as it's probably a slightly obscure class...)
1 parent b7b8f5b commit 5cbd04c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lib/matplotlib/colorbar.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,17 @@
141141
Parameters
142142
----------
143143
mappable
144-
The `~matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.Image`,
145-
`~matplotlib.contour.ContourSet`, etc.) to which the colorbar applies.
144+
The `matplotlib.cm.ScalarMappable` (i.e., `~matplotlib.image.Image`,
145+
`~matplotlib.contour.ContourSet`, etc.) described by this colorbar.
146146
This argument is mandatory for the `.Figure.colorbar` method but optional
147147
for the `.pyplot.colorbar` function, which sets the default to the current
148148
image.
149149
150+
Note that one can create a `ScalarMappable` "on-the-fly" to generate
151+
colorbars not attached to a previously drawn artist, e.g. ::
152+
153+
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap, ax=ax))
154+
150155
cax : :class:`~matplotlib.axes.Axes` object, optional
151156
Axes into which the colorbar will be drawn.
152157

0 commit comments

Comments
 (0)