Add a colorbar to a plot. Parameters ---------- mappable The `matplotlib.colorizer.ColorizingArtist` (i.e., `.AxesImage`, `.ContourSet`, etc.) described by this colorbar. This argument is mandatory for the `.Figure.colorbar` meth
(
self, mappable, cax=None, ax=None, use_gridspec=True, **kwargs)
| 1200 | |
| 1201 | @_docstring.interpd |
| 1202 | def colorbar( |
| 1203 | self, mappable, cax=None, ax=None, use_gridspec=True, **kwargs): |
| 1204 | """ |
| 1205 | Add a colorbar to a plot. |
| 1206 | |
| 1207 | Parameters |
| 1208 | ---------- |
| 1209 | mappable |
| 1210 | The `matplotlib.colorizer.ColorizingArtist` (i.e., `.AxesImage`, |
| 1211 | `.ContourSet`, etc.) described by this colorbar. This argument is |
| 1212 | mandatory for the `.Figure.colorbar` method but optional for the |
| 1213 | `.pyplot.colorbar` function, which sets the default to the current |
| 1214 | image. |
| 1215 | |
| 1216 | Note that one can create a `.colorizer.ColorizingArtist` "on-the-fly" |
| 1217 | to generate colorbars not attached to a previously drawn artist, e.g. |
| 1218 | :: |
| 1219 | |
| 1220 | cr = colorizer.Colorizer(norm=norm, cmap=cmap) |
| 1221 | fig.colorbar(colorizer.ColorizingArtist(cr), ax=ax) |
| 1222 | |
| 1223 | cax : `~matplotlib.axes.Axes`, optional |
| 1224 | Axes into which the colorbar will be drawn. If `None`, then a new |
| 1225 | Axes is created and the space for it will be stolen from the Axes(s) |
| 1226 | specified in *ax*. |
| 1227 | |
| 1228 | ax : `~matplotlib.axes.Axes` or iterable or `numpy.ndarray` of Axes, optional |
| 1229 | The one or more parent Axes from which space for a new colorbar Axes |
| 1230 | will be stolen. This parameter is only used if *cax* is not set. |
| 1231 | |
| 1232 | Defaults to the Axes that contains the mappable used to create the |
| 1233 | colorbar. |
| 1234 | |
| 1235 | use_gridspec : bool, optional |
| 1236 | If *cax* is ``None``, a new *cax* is created as an instance of |
| 1237 | Axes. If *ax* is positioned with a subplotspec and *use_gridspec* |
| 1238 | is ``True``, then *cax* is also positioned with a subplotspec. |
| 1239 | |
| 1240 | Returns |
| 1241 | ------- |
| 1242 | colorbar : `~matplotlib.colorbar.Colorbar` |
| 1243 | |
| 1244 | Other Parameters |
| 1245 | ---------------- |
| 1246 | %(_make_axes_kw_doc)s |
| 1247 | %(_colormap_kw_doc)s |
| 1248 | |
| 1249 | Notes |
| 1250 | ----- |
| 1251 | If *mappable* is a `~.contour.ContourSet`, its *extend* kwarg is |
| 1252 | included automatically. |
| 1253 | |
| 1254 | The *shrink* kwarg provides a simple way to scale the colorbar with |
| 1255 | respect to the Axes. Note that if *cax* is specified, it determines the |
| 1256 | size of the colorbar, and *shrink* and *aspect* are ignored. |
| 1257 | |
| 1258 | For more precise control, you can manually specify the positions of the |
| 1259 | axes objects in which the mappable and the colorbar are drawn. In this |