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

Skip to content

Commit 14a0cfd

Browse files
committed
Permit passing legend label for single-color parametric line
1 parent 0bf2c90 commit 14a0cfd

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

‎proplot/axes/plot.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -375,16 +375,24 @@
375375

376376

377377
# Labels docstrings
378-
_labels_1d_docstring = """
378+
_label_docstring = """
379379
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
382386
labels, values : sequence of float or sequence of str, optional
383387
The legend labels or colorbar coordinates used for each plotted element.
384388
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.
386390
"""
387391
_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`.
388396
labels : bool, optional
389397
Whether to apply labels to contours and grid boxes. The text will be
390398
white when the luminance of the underlying filled contour or grid box
@@ -394,17 +402,13 @@
394402
For contour plots, this is passed to `~matplotlib.axes.Axes.clabel`.
395403
Otherwise, this is passed to `~matplotlib.axes.Axes.text`.
396404
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.
399407
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`.
407410
"""
411+
docstring._snippet_manager['plot.label'] = _label_docstring
408412
docstring._snippet_manager['plot.labels_1d'] = _labels_1d_docstring
409413
docstring._snippet_manager['plot.labels_2d'] = _labels_2d_docstring
410414

@@ -558,7 +562,7 @@
558562
Parameters
559563
----------
560564
%(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
562566
The parametric coordinate(s). These can be passed as a third positional
563567
argument or as a keyword argument. If they are float, the colors will be
564568
determined from `norm` and `cmap`. If they are strings, the color values
@@ -580,6 +584,7 @@
580584
scalex, scaley : bool, optional
581585
Whether the view limits are adapted to the data limits. The values are
582586
passed on to `~matplotlib.axes.Axes.autoscale_view`.
587+
%(plot.label)s
583588
%(plot.guide)s
584589
**kwargs
585590
Valid `~matplotlib.collections.LineCollection` properties.
@@ -2913,6 +2918,7 @@ def parametric(self, x, y, c, *, interp=0, scalex=True, scaley=True, **kwargs):
29132918
kw = kwargs.copy()
29142919
kw.update(_pop_props(kw, 'collection'))
29152920
kw, extents = self._parse_inbounds(**kw)
2921+
label = _not_none(**{key: kw.pop(key, None) for key in ('label', 'value')})
29162922
x, y, kw = self._parse_plot1d(x, y, values=c, autovalues=True, autoreverse=False, **kw) # noqa: E501
29172923
c = kw.pop('values', None) # permits auto-inferring values
29182924
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):
29732979
# backwards compatible to earliest matplotlib versions.
29742980
guide_kw = _pop_params(kw, self._update_guide)
29752981
obj = mcollections.LineCollection(
2976-
coords, cmap=cmap, norm=norm,
2982+
coords, cmap=cmap, norm=norm, label=label,
29772983
linestyles='-', capstyle='butt', joinstyle='miter',
29782984
)
29792985
obj.set_array(c) # the ScalarMappable method
29802986
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
29822988
self.autoscale_view(scalex=scalex, scaley=scaley)
29832989
self._update_guide(obj, **guide_kw)
29842990
return obj

0 commit comments

Comments
 (0)