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

Skip to content

Commit 0414b3f

Browse files
committed
Use super() more in collections and containers.
1 parent 9fe9820 commit 0414b3f

File tree

4 files changed

+29
-34
lines changed

4 files changed

+29
-34
lines changed

lib/matplotlib/collections.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def set_sizes(self, sizes, dpi=72.0):
930930
@artist.allow_rasterization
931931
def draw(self, renderer):
932932
self.set_sizes(self._sizes, self.figure.dpi)
933-
Collection.draw(self, renderer)
933+
super().draw(renderer)
934934

935935

936936
class PathCollection(_CollectionWithSizes):
@@ -1122,7 +1122,7 @@ def __init__(self, verts, sizes=None, closed=True, **kwargs):
11221122
**kwargs
11231123
Forwarded to `.Collection`.
11241124
"""
1125-
Collection.__init__(self, **kwargs)
1125+
super().__init__(**kwargs)
11261126
self.set_sizes(sizes)
11271127
self.set_verts(verts, closed)
11281128
self.stale = True
@@ -1212,7 +1212,7 @@ def __init__(self, xranges, yrange, **kwargs):
12121212
(xmin + xwidth, ymax),
12131213
(xmin + xwidth, ymin),
12141214
(xmin, ymin)] for xmin, xwidth in xranges]
1215-
PolyCollection.__init__(self, verts, **kwargs)
1215+
super().__init__(verts, **kwargs)
12161216

12171217
@classmethod
12181218
def span_where(cls, x, ymin, ymax, where, **kwargs):
@@ -1272,7 +1272,7 @@ def __init__(self,
12721272
transOffset=ax.transData,
12731273
)
12741274
"""
1275-
Collection.__init__(self, **kwargs)
1275+
super().__init__(**kwargs)
12761276
self.set_sizes(sizes)
12771277
self._numsides = numsides
12781278
self._paths = [self._path_generator(numsides)]
@@ -1292,6 +1292,8 @@ def draw(self, renderer):
12921292
transforms.Affine2D(x).rotate(-self._rotation).get_matrix()
12931293
for x in self._transforms
12941294
]
1295+
# Explicitly not super().draw, because set_sizes must be called before
1296+
# updating self._transforms.
12951297
Collection.draw(self, renderer)
12961298

12971299

@@ -1378,8 +1380,7 @@ def __init__(self, segments, # Can be None.
13781380
antialiaseds = (mpl.rcParams['lines.antialiased'],)
13791381

13801382
colors = mcolors.to_rgba_array(colors)
1381-
Collection.__init__(
1382-
self,
1383+
super().__init__(
13831384
edgecolors=colors,
13841385
facecolors=facecolors,
13851386
linewidths=linewidths,
@@ -1520,13 +1521,10 @@ def __init__(self,
15201521
--------
15211522
.. plot:: gallery/lines_bars_and_markers/eventcollection_demo.py
15221523
"""
1523-
LineCollection.__init__(self,
1524-
[],
1525-
linewidths=linewidth,
1526-
colors=color,
1527-
antialiaseds=antialiased,
1528-
linestyles=linestyle,
1529-
**kwargs)
1524+
super().__init__([],
1525+
linewidths=linewidth, linestyles=linestyle,
1526+
colors=color, antialiaseds=antialiased,
1527+
**kwargs)
15301528
self._is_horizontal = True # Initial value, may be switched below.
15311529
self._linelength = linelength
15321530
self._lineoffset = lineoffset
@@ -1677,7 +1675,7 @@ def __init__(self, sizes, **kwargs):
16771675
**kwargs
16781676
Forwarded to `.Collection`.
16791677
"""
1680-
Collection.__init__(self, **kwargs)
1678+
super().__init__(**kwargs)
16811679
self.set_sizes(sizes)
16821680
self.set_transform(transforms.IdentityTransform())
16831681
self._paths = [mpath.Path.unit_circle()]
@@ -1711,7 +1709,7 @@ def __init__(self, widths, heights, angles, units='points', **kwargs):
17111709
**kwargs
17121710
Forwarded to `Collection`.
17131711
"""
1714-
Collection.__init__(self, **kwargs)
1712+
super().__init__(**kwargs)
17151713
self._widths = 0.5 * np.asarray(widths).ravel()
17161714
self._heights = 0.5 * np.asarray(heights).ravel()
17171715
self._angles = np.deg2rad(angles).ravel()
@@ -1765,7 +1763,7 @@ def _set_transforms(self):
17651763
@artist.allow_rasterization
17661764
def draw(self, renderer):
17671765
self._set_transforms()
1768-
Collection.draw(self, renderer)
1766+
super().draw(renderer)
17691767

17701768

17711769
class PatchCollection(Collection):
@@ -1813,7 +1811,7 @@ def determine_facecolor(patch):
18131811
kwargs['linestyles'] = [p.get_linestyle() for p in patches]
18141812
kwargs['antialiaseds'] = [p.get_antialiased() for p in patches]
18151813

1816-
Collection.__init__(self, **kwargs)
1814+
super().__init__(**kwargs)
18171815

18181816
self.set_paths(patches)
18191817

@@ -1830,7 +1828,7 @@ class TriMesh(Collection):
18301828
A triangular mesh is a `~matplotlib.tri.Triangulation` object.
18311829
"""
18321830
def __init__(self, triangulation, **kwargs):
1833-
Collection.__init__(self, **kwargs)
1831+
super().__init__(**kwargs)
18341832
self._triangulation = triangulation
18351833
self._shading = 'gouraud'
18361834
self._is_filled = True
@@ -1918,7 +1916,7 @@ class QuadMesh(Collection):
19181916
"""
19191917
def __init__(self, meshWidth, meshHeight, coordinates,
19201918
antialiased=True, shading='flat', **kwargs):
1921-
Collection.__init__(self, **kwargs)
1919+
super().__init__(**kwargs)
19221920
self._meshWidth = meshWidth
19231921
self._meshHeight = meshHeight
19241922
# By converting to floats now, we can avoid that on every draw.

lib/matplotlib/container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BarContainer(Container):
6565
def __init__(self, patches, errorbar=None, **kwargs):
6666
self.patches = patches
6767
self.errorbar = errorbar
68-
Container.__init__(self, patches, **kwargs)
68+
super().__init__(patches, **kwargs)
6969

7070

7171
class ErrorbarContainer(Container):
@@ -97,7 +97,7 @@ def __init__(self, lines, has_xerr=False, has_yerr=False, **kwargs):
9797
self.lines = lines
9898
self.has_xerr = has_xerr
9999
self.has_yerr = has_yerr
100-
Container.__init__(self, lines, **kwargs)
100+
super().__init__(lines, **kwargs)
101101

102102

103103
class StemContainer(Container):
@@ -132,4 +132,4 @@ def __init__(self, markerline_stemlines_baseline, **kwargs):
132132
self.markerline = markerline
133133
self.stemlines = stemlines
134134
self.baseline = baseline
135-
Container.__init__(self, markerline_stemlines_baseline, **kwargs)
135+
super().__init__(markerline_stemlines_baseline, **kwargs)

lib/matplotlib/quiver.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,8 @@ def __init__(self, ax, *args,
495495
self.transform = kw.pop('transform', ax.transData)
496496
kw.setdefault('facecolors', color)
497497
kw.setdefault('linewidths', (0,))
498-
mcollections.PolyCollection.__init__(self, [], offsets=self.XY,
499-
transOffset=self.transform,
500-
closed=False,
501-
**kw)
498+
super().__init__([], offsets=self.XY, transOffset=self.transform,
499+
closed=False, **kw)
502500
self.polykw = kw
503501
self.set_UVC(U, V, C)
504502
self._initialized = False
@@ -561,7 +559,7 @@ def draw(self, renderer):
561559
verts = self._make_verts(self.U, self.V, self.angles)
562560
self.set_verts(verts, closed=False)
563561
self._new_UV = False
564-
mcollections.PolyCollection.draw(self, renderer)
562+
super().draw(renderer)
565563
self.stale = False
566564

567565
def set_UVC(self, U, V, C=None):
@@ -971,9 +969,8 @@ def __init__(self, ax, *args,
971969

972970
# Make a collection
973971
barb_size = self._length ** 2 / 4 # Empirically determined
974-
mcollections.PolyCollection.__init__(self, [], (barb_size,),
975-
offsets=xy,
976-
transOffset=transform, **kw)
972+
super().__init__([], (barb_size,), offsets=xy, transOffset=transform,
973+
**kw)
977974
self.set_transform(transforms.IdentityTransform())
978975

979976
self.set_UVC(u, v, c)
@@ -1213,7 +1210,7 @@ def set_offsets(self, xy):
12131210
self.x.ravel(), self.y.ravel(), self.u, self.v)
12141211
_check_consistent_shapes(x, y, u, v)
12151212
xy = np.column_stack((x, y))
1216-
mcollections.PolyCollection.set_offsets(self, xy)
1213+
super().set_offsets(xy)
12171214
self.stale = True
12181215

12191216
barbs_doc = _barbs_doc

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ def set_verts(self, verts, closed=True):
624624
"""Set 3D vertices."""
625625
self.get_vector(verts)
626626
# 2D verts will be updated at draw time
627-
PolyCollection.set_verts(self, [], False)
627+
super().set_verts([], False)
628628
self._closed = closed
629629

630630
def set_verts_and_codes(self, verts, codes):
@@ -707,11 +707,11 @@ def do_3d_projection(self, renderer):
707707
return np.nan
708708

709709
def set_facecolor(self, colors):
710-
PolyCollection.set_facecolor(self, colors)
710+
super().set_facecolor(colors)
711711
self._facecolors3d = PolyCollection.get_facecolor(self)
712712

713713
def set_edgecolor(self, colors):
714-
PolyCollection.set_edgecolor(self, colors)
714+
super().set_edgecolor(colors)
715715
self._edgecolors3d = PolyCollection.get_edgecolor(self)
716716

717717
def set_alpha(self, alpha):

0 commit comments

Comments
 (0)