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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,22 @@ class silent_list(list):
one will get ::

<a list of 3 Line2D objects>

If ``self.type`` is None, the type name is obtained from the first item in
the list (if any).
"""

def __init__(self, type, seq=None):
self.type = type
if seq is not None:
self.extend(seq)

def __repr__(self):
return '<a list of %d %s objects>' % (len(self), self.type)
if self.type is not None or len(self) != 0:
tp = self.type if self.type is not None else type(self[0]).__name__
return f"<a list of {len(self)} {tp} objects>"
else:
return "<an empty list>"


@deprecated("3.3")
Expand Down
39 changes: 16 additions & 23 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,10 +845,8 @@ def __init__(self, ax, *args,
if extend_max:
cmap.set_over(self.colors[-1])

if self.filled:
self.collections = cbook.silent_list('mcoll.PathCollection')
else:
self.collections = cbook.silent_list('mcoll.LineCollection')
self.collections = cbook.silent_list(None)

# label lists must be initialized here
self.labelTexts = []
self.labelCValues = []
Expand All @@ -869,53 +867,48 @@ def __init__(self, ax, *args,
if self.filled:
if self.linewidths is not None:
cbook._warn_external('linewidths is ignored by contourf')

# Lower and upper contour levels.
lowers, uppers = self._get_lowers_and_uppers()

# Ensure allkinds can be zipped below.
if self.allkinds is None:
self.allkinds = [None] * len(self.allsegs)

# Default zorder taken from Collection
self._contour_zorder = kwargs.pop('zorder', 1)
for level, level_upper, segs, kinds in \
zip(lowers, uppers, self.allsegs, self.allkinds):
paths = self._make_paths(segs, kinds)

col = mcoll.PathCollection(
paths,
self.collections[:] = [
mcoll.PathCollection(
self._make_paths(segs, kinds),
antialiaseds=(self.antialiased,),
edgecolors='none',
alpha=self.alpha,
transform=self.get_transform(),
zorder=self._contour_zorder)
self.axes.add_collection(col, autolim=False)
self.collections.append(col)
for level, level_upper, segs, kinds
in zip(lowers, uppers, self.allsegs, self.allkinds)]
else:
tlinewidths = self._process_linewidths()
self.tlinewidths = tlinewidths
self.tlinewidths = tlinewidths = self._process_linewidths()
tlinestyles = self._process_linestyles()
aa = self.antialiased
if aa is not None:
aa = (self.antialiased,)
# Default zorder taken from LineCollection
self._contour_zorder = kwargs.pop('zorder', 2)
for level, width, lstyle, segs in \
zip(self.levels, tlinewidths, tlinestyles, self.allsegs):
col = mcoll.LineCollection(

self.collections[:] = [
mcoll.LineCollection(
segs,
antialiaseds=aa,
linewidths=width,
linestyles=[lstyle],
alpha=self.alpha,
transform=self.get_transform(),
zorder=self._contour_zorder)
col.set_label('_nolegend_')
self.axes.add_collection(col, autolim=False)
self.collections.append(col)
zorder=self._contour_zorder,
label='_nolegend_')
for level, width, lstyle, segs
in zip(self.levels, tlinewidths, tlinestyles, self.allsegs)]

for col in self.collections:
self.axes.add_collection(col, autolim=False)
col.sticky_edges.x[:] = [self._mins[0], self._maxs[0]]
col.sticky_edges.y[:] = [self._mins[1], self._maxs[1]]
self.axes.update_datalim([self._mins, self._maxs])
Expand Down