diff --git a/lib/matplotlib/container.py b/lib/matplotlib/container.py index a58e55ca196c..21197f9faa12 100644 --- a/lib/matplotlib/container.py +++ b/lib/matplotlib/container.py @@ -1,3 +1,5 @@ +import collections + from matplotlib import cbook from matplotlib.artist import Artist @@ -15,7 +17,12 @@ def __repr__(self): .format(type(self).__name__, len(self))) def __new__(cls, *args, **kwargs): - return tuple.__new__(cls, args[0]) + if isinstance(args[0], collections.abc.Iterable): + iterable_of_artists = args[0] + else: + iterable_of_artists = (a for a in args if isinstance(a, Artist)) + + return tuple.__new__(cls, iterable_of_artists) def __init__(self, kl, label=None): self._callbacks = cbook.CallbackRegistry(signals=["pchanged"]) diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index f4cd1becf113..56ebb0ec3f33 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -7,6 +7,7 @@ import matplotlib as mpl from matplotlib import _api, cm, patches +from matplotlib.container import Container import matplotlib.colors as mcolors import matplotlib.collections as mcollections import matplotlib.lines as mlines @@ -76,17 +77,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, Returns ------- - StreamplotSet - Container object with attributes + `~.StreamplotContainer` - - ``lines``: `.LineCollection` of streamlines - - - ``arrows``: `.PatchCollection` containing `.FancyArrowPatch` - objects representing the arrows half-way along stream lines. - - This container will probably change in the future to allow changes - to the colormap, alpha, etc. for both lines and arrows, but these - changes should be backward compatible. + .. versionchanged major.minor:: """ grid = Grid(x, y) mask = StreamMask(density) @@ -237,20 +230,35 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, axes.add_patch(p) axes.autoscale_view() - stream_container = StreamplotSet(lc, ac) - return stream_container + return StreamplotSet(lc, ac) + + +class StreamplotSet(Container): + """ + `~.Container` object for artists created in an `~.Axes.streamplot` plot. + It can be treated like a namedtuple with fields ``(lines, arrows)`` -class StreamplotSet: + .. versionchanged major.minor :: - def __init__(self, lines, arrows): + Attributes + ---------- + lines: `~.LineCollection` +` collection of `.Line2d` segments that make up the streamlines + arrows: `~.PatchCollection` + collection of `.FancyArrow` arrows half-way along each streamline + """ + + def __init__(self, lines, arrows, **kwargs): self.lines = lines self.arrows = arrows + super().__init__(lines, arrows, **kwargs) # Coordinate definitions # ======================== + class DomainMap: """ Map representing different coordinate systems.