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

Skip to content

Commit 9ceaf75

Browse files
committed
Use super() in color-related classes.
1 parent ebc784f commit 9ceaf75

5 files changed

Lines changed: 14 additions & 15 deletions

File tree

examples/userdemo/colormap_normalizations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
class MidpointNormalize(colors.Normalize):
9595
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
9696
self.midpoint = midpoint
97-
colors.Normalize.__init__(self, vmin, vmax, clip)
97+
super().__init__(vmin, vmax, clip)
9898

9999
def __call__(self, value, clip=None):
100100
# I'm ignoring masked values and all kinds of edge cases to make a

lib/matplotlib/colorbar.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,15 +1218,15 @@ def __init__(self, ax, mappable, **kwargs):
12181218
)
12191219
kwargs.setdefault(
12201220
'ticks', ticker.FixedLocator(cs.levels, nbins=10))
1221-
ColorbarBase.__init__(self, ax, **kwargs)
1221+
super().__init__(ax, **kwargs)
12221222
if not cs.filled:
12231223
self.add_lines(cs)
12241224
else:
12251225
if getattr(mappable.cmap, 'colorbar_extend', False) is not False:
12261226
kwargs.setdefault('extend', mappable.cmap.colorbar_extend)
12271227
if isinstance(mappable, martist.Artist):
12281228
_add_disjoint_kwargs(kwargs, alpha=mappable.get_alpha())
1229-
ColorbarBase.__init__(self, ax, **kwargs)
1229+
super().__init__(ax, **kwargs)
12301230

12311231
@cbook.deprecated("3.3", alternative="update_normal")
12321232
def on_mappable_changed(self, mappable):
@@ -1256,8 +1256,7 @@ def add_lines(self, CS, erase=True):
12561256
tcolors = [c[0] for c in CS.tcolors]
12571257
tlinewidths = [t[0] for t in CS.tlinewidths]
12581258
# Wishlist: Make colorbar lines auto-follow changes in contour lines.
1259-
ColorbarBase.add_lines(self, CS.levels, tcolors, tlinewidths,
1260-
erase=erase)
1259+
super().add_lines(CS.levels, tcolors, tlinewidths, erase=erase)
12611260

12621261
def update_normal(self, mappable):
12631262
"""
@@ -1338,7 +1337,7 @@ def remove(self):
13381337
If the colorbar was created with ``use_gridspec=True`` the previous
13391338
gridspec is restored.
13401339
"""
1341-
ColorbarBase.remove(self)
1340+
super().remove()
13421341
self.mappable.callbacksSM.disconnect(self.mappable.colorbar_cid)
13431342
self.mappable.colorbar = None
13441343
self.mappable.colorbar_cid = None
@@ -1606,7 +1605,7 @@ def __init__(self, ax, mappable, **kw):
16061605
# so add a new attribute which will be a list of the
16071606
# colored patches in the colorbar
16081607
self.solids_patches = []
1609-
Colorbar.__init__(self, ax, mappable, **kw)
1608+
super().__init__(ax, mappable, **kw)
16101609

16111610
def _add_solids(self, X, Y, C):
16121611
"""

lib/matplotlib/colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def __init__(self, name, segmentdata, N=256, gamma=1.0):
782782
"""
783783
# True only if all colors in map are identical; needed for contouring.
784784
self.monochrome = False
785-
Colormap.__init__(self, name, N)
785+
super().__init__(name, N)
786786
self._segmentdata = segmentdata
787787
self._gamma = gamma
788788

@@ -940,7 +940,7 @@ def __init__(self, colors, name='from_list', N=None):
940940
else:
941941
self.colors = [gray] * N
942942
self.monochrome = True
943-
Colormap.__init__(self, name, N)
943+
super().__init__(name, N)
944944

945945
def _init(self):
946946
self._lut = np.zeros((self.N + 3, 4), float)
@@ -1335,7 +1335,7 @@ class PowerNorm(Normalize):
13351335
a power-law normalization over that range.
13361336
"""
13371337
def __init__(self, gamma, vmin=None, vmax=None, clip=False):
1338-
Normalize.__init__(self, vmin, vmax, clip)
1338+
super().__init__(vmin, vmax, clip)
13391339
self.gamma = gamma
13401340

13411341
def __call__(self, value, clip=None):

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def __init__(self, ax,
334334
if norm is None:
335335
norm = colors.Normalize()
336336
self.alpha = alpha
337-
cm.ScalarMappable.__init__(self, cmap=cmap, norm=norm)
337+
super().__init__(cmap=cmap, norm=norm)
338338
self.values = values
339339
self.boundaries = boundaries
340340
self.extend = extend
@@ -671,11 +671,11 @@ def __init__(self, ax, mappable, **kw):
671671
#kw['ticks'] = CS._levels
672672
kw.setdefault('ticks', ticker.FixedLocator(CS.levels, nbins=10))
673673
kw['filled'] = CS.filled
674-
ColorbarBase.__init__(self, ax, **kw)
674+
super().__init__(ax, **kw)
675675
if not CS.filled:
676676
self.add_lines(CS)
677677
else:
678-
ColorbarBase.__init__(self, ax, **kw)
678+
super().__init__(ax, **kw)
679679

680680
def add_lines(self, CS):
681681
"""Add the lines from a non-filled `.ContourSet` to the colorbar."""
@@ -690,7 +690,7 @@ def add_lines(self, CS):
690690
# to make one object track another automatically.
691691
#tcolors = [col.get_colors()[0] for col in CS.collections]
692692
#tlinewidths = [col.get_linewidth()[0] for lw in CS.collections]
693-
ColorbarBase.add_lines(self, CS.levels, tcolors, tlinewidths)
693+
super().add_lines(CS.levels, tcolors, tlinewidths)
694694

695695
def update_normal(self, mappable):
696696
"""

tutorials/colors/colormapnorms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
class MidpointNormalize(colors.Normalize):
248248
def __init__(self, vmin=None, vmax=None, vcenter=None, clip=False):
249249
self.vcenter = vcenter
250-
colors.Normalize.__init__(self, vmin, vmax, clip)
250+
super().__init__(vmin, vmax, clip)
251251

252252
def __call__(self, value, clip=None):
253253
# I'm ignoring masked values and all kinds of edge cases to make a

0 commit comments

Comments
 (0)