|
375 | 375 |
|
376 | 376 |
|
377 | 377 | # Labels docstrings
|
378 |
| -_labels_1d_docstring = """ |
| 378 | +_label_docstring = """ |
379 | 379 | label, value : float or str, optional
|
380 |
| - The single legend label or colorbar coordinate to be used for this plotted |
381 |
| - element. This is generally used with 1D input coordinates. |
| 380 | + The single legend label or colorbar coordinate to be used for |
| 381 | + this plotted element. Can be numeric or string. This is generally |
| 382 | + used with 1D positional arguments. |
| 383 | +""" |
| 384 | +_labels_1d_docstring = """ |
| 385 | +%(plot.label)s |
382 | 386 | labels, values : sequence of float or sequence of str, optional
|
383 | 387 | The legend labels or colorbar coordinates used for each plotted element.
|
384 | 388 | Can be numeric or string, and must match the number of plotted elements.
|
385 |
| - This is generally used with 2D input coordinates. |
| 389 | + This is generally used with 2D positional arguments. |
386 | 390 | """
|
387 | 391 | _labels_2d_docstring = """
|
| 392 | +label : str, optional |
| 393 | + The legend label to be used for this object. In the case of |
| 394 | + contours, this is paired with the the central artist in the artist |
| 395 | + list returned by `matplotlib.contour.ContourSet.legend_elements`. |
388 | 396 | labels : bool, optional
|
389 | 397 | Whether to apply labels to contours and grid boxes. The text will be
|
390 | 398 | white when the luminance of the underlying filled contour or grid box
|
|
394 | 402 | For contour plots, this is passed to `~matplotlib.axes.Axes.clabel`.
|
395 | 403 | Otherwise, this is passed to `~matplotlib.axes.Axes.text`.
|
396 | 404 | fmt : format-spec, optional
|
397 |
| - Passed to the `~proplot.constructor.Norm` constructor, used to format |
398 |
| - number labels. You can also use the `precision` keyword arg. |
| 405 | + The `~matplotlib.ticker.Formatter` used to format number labels. |
| 406 | + Passed to the `~proplot.constructor.Formatter` constructor. |
399 | 407 | precision : int, optional
|
400 |
| - Maximum number of decimal places for the number labels. Number labels |
401 |
| - are generated with the `~proplot.ticker.SimpleFormatter` formatter, |
402 |
| - which permits limiting the precision. |
403 |
| -label : str, optional |
404 |
| - The legend label to be used for this object. In the case of |
405 |
| - contours, this is paired with the the central artist in the artist |
406 |
| - list returned by `matplotlib.contour.ContourSet.legend_elements`. |
| 408 | + The maximum number of decimal places for number labels generated |
| 409 | + with the default formatter `~proplot.ticker.Simpleformatter`. |
407 | 410 | """
|
| 411 | +docstring._snippet_manager['plot.label'] = _label_docstring |
408 | 412 | docstring._snippet_manager['plot.labels_1d'] = _labels_1d_docstring
|
409 | 413 | docstring._snippet_manager['plot.labels_2d'] = _labels_2d_docstring
|
410 | 414 |
|
|
558 | 562 | Parameters
|
559 | 563 | ----------
|
560 | 564 | %(plot.args_1d_y)s
|
561 |
| -c, color, colors, values : sequence of float, str, or color-spec, optional |
| 565 | +c, color, colors, values, labels : sequence of float, str, or color-spec, optional |
562 | 566 | The parametric coordinate(s). These can be passed as a third positional
|
563 | 567 | argument or as a keyword argument. If they are float, the colors will be
|
564 | 568 | determined from `norm` and `cmap`. If they are strings, the color values
|
|
580 | 584 | scalex, scaley : bool, optional
|
581 | 585 | Whether the view limits are adapted to the data limits. The values are
|
582 | 586 | passed on to `~matplotlib.axes.Axes.autoscale_view`.
|
| 587 | +%(plot.label)s |
583 | 588 | %(plot.guide)s
|
584 | 589 | **kwargs
|
585 | 590 | Valid `~matplotlib.collections.LineCollection` properties.
|
@@ -2913,6 +2918,7 @@ def parametric(self, x, y, c, *, interp=0, scalex=True, scaley=True, **kwargs):
|
2913 | 2918 | kw = kwargs.copy()
|
2914 | 2919 | kw.update(_pop_props(kw, 'collection'))
|
2915 | 2920 | kw, extents = self._parse_inbounds(**kw)
|
| 2921 | + label = _not_none(**{key: kw.pop(key, None) for key in ('label', 'value')}) |
2916 | 2922 | x, y, kw = self._parse_plot1d(x, y, values=c, autovalues=True, autoreverse=False, **kw) # noqa: E501
|
2917 | 2923 | c = kw.pop('values', None) # permits auto-inferring values
|
2918 | 2924 | c = np.arange(y.size) if c is None else data._to_numpy_array(c)
|
@@ -2973,12 +2979,12 @@ def parametric(self, x, y, c, *, interp=0, scalex=True, scaley=True, **kwargs):
|
2973 | 2979 | # backwards compatible to earliest matplotlib versions.
|
2974 | 2980 | guide_kw = _pop_params(kw, self._update_guide)
|
2975 | 2981 | obj = mcollections.LineCollection(
|
2976 |
| - coords, cmap=cmap, norm=norm, |
| 2982 | + coords, cmap=cmap, norm=norm, label=label, |
2977 | 2983 | linestyles='-', capstyle='butt', joinstyle='miter',
|
2978 | 2984 | )
|
2979 | 2985 | obj.set_array(c) # the ScalarMappable method
|
2980 | 2986 | obj.update({key: value for key, value in kw.items() if key not in ('color',)})
|
2981 |
| - self.add_collection(obj) |
| 2987 | + self.add_collection(obj) # also adjusts label |
2982 | 2988 | self.autoscale_view(scalex=scalex, scaley=scaley)
|
2983 | 2989 | self._update_guide(obj, **guide_kw)
|
2984 | 2990 | return obj
|
|
0 commit comments