From fb3ea5eea6e0873dc8d469ab0f3ecd4dcdb1c4a1 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 19 Dec 2019 11:20:44 +0100 Subject: [PATCH] Cleanup span_where. - Make it a classmethod so that if called through a subclass, that subclass is returned. - Reword a bit the docstring (I think it's the kind of cases where non-numpydoc is actually more readable...). --- lib/matplotlib/collections.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index cd59e5e56d37..36aa6a6eb617 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -1155,15 +1155,14 @@ def __init__(self, xranges, yrange, **kwargs): (xmin, ymin)] for xmin, xwidth in xranges] PolyCollection.__init__(self, verts, **kwargs) - @staticmethod - def span_where(x, ymin, ymax, where, **kwargs): + @classmethod + def span_where(cls, x, ymin, ymax, where, **kwargs): """ - Create a BrokenBarHCollection to plot horizontal bars from + Return a `BrokenBarHCollection` that plots horizontal bars from over the regions in *x* where *where* is True. The bars range on the y-axis from *ymin* to *ymax* - A :class:`BrokenBarHCollection` is returned. *kwargs* are - passed on to the collection. + *kwargs* are passed on to the collection. """ xranges = [] for ind0, ind1 in cbook.contiguous_regions(where): @@ -1171,10 +1170,7 @@ def span_where(x, ymin, ymax, where, **kwargs): if not len(xslice): continue xranges.append((xslice[0], xslice[-1] - xslice[0])) - - collection = BrokenBarHCollection( - xranges, [ymin, ymax - ymin], **kwargs) - return collection + return cls(xranges, [ymin, ymax - ymin], **kwargs) class RegularPolyCollection(_CollectionWithSizes):