Get the handles and labels from the calls to either ``figure.legend`` or ``axes.legend``. The parser is a bit involved because we support:: legend() legend(labels) legend(handles, labels) legend(labels=labels) legend(handles=handles) leg
(axs, *args, handles=None, labels=None, **kwargs)
| 1306 | |
| 1307 | |
| 1308 | def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs): |
| 1309 | """ |
| 1310 | Get the handles and labels from the calls to either ``figure.legend`` |
| 1311 | or ``axes.legend``. |
| 1312 | |
| 1313 | The parser is a bit involved because we support:: |
| 1314 | |
| 1315 | legend() |
| 1316 | legend(labels) |
| 1317 | legend(handles, labels) |
| 1318 | legend(labels=labels) |
| 1319 | legend(handles=handles) |
| 1320 | legend(handles=handles, labels=labels) |
| 1321 | |
| 1322 | The behavior for a mixture of positional and keyword handles and labels |
| 1323 | is undefined and raises an error. |
| 1324 | |
| 1325 | Parameters |
| 1326 | ---------- |
| 1327 | axs : list of `.Axes` |
| 1328 | If handles are not given explicitly, the artists in these Axes are |
| 1329 | used as handles. |
| 1330 | *args : tuple |
| 1331 | Positional parameters passed to ``legend()``. |
| 1332 | handles |
| 1333 | The value of the keyword argument ``legend(handles=...)``, or *None* |
| 1334 | if that keyword argument was not used. |
| 1335 | labels |
| 1336 | The value of the keyword argument ``legend(labels=...)``, or *None* |
| 1337 | if that keyword argument was not used. |
| 1338 | **kwargs |
| 1339 | All other keyword arguments passed to ``legend()``. |
| 1340 | |
| 1341 | Returns |
| 1342 | ------- |
| 1343 | handles : list of (`.Artist` or tuple of `.Artist`) |
| 1344 | The legend handles. |
| 1345 | labels : list of str |
| 1346 | The legend labels. |
| 1347 | kwargs : dict |
| 1348 | *kwargs* with keywords handles and labels removed. |
| 1349 | |
| 1350 | """ |
| 1351 | log = logging.getLogger(__name__) |
| 1352 | |
| 1353 | handlers = kwargs.get('handler_map') |
| 1354 | |
| 1355 | if (handles is not None or labels is not None) and args: |
| 1356 | raise TypeError("When passing handles and labels, they must both be " |
| 1357 | "passed positionally or both as keywords.") |
| 1358 | |
| 1359 | if (hasattr(handles, "__len__") and |
| 1360 | hasattr(labels, "__len__") and |
| 1361 | len(handles) != len(labels)): |
| 1362 | _api.warn_external(f"Mismatched number of handles and labels: " |
| 1363 | f"len(handles) = {len(handles)} " |
| 1364 | f"len(labels) = {len(labels)}") |
| 1365 | # if got both handles and labels as kwargs, make same length |
nothing calls this directly
no test coverage detected
searching dependent graphs…