Skip to content

Inline ContourSet._make_paths. #25121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 2, 2023
Merged
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
42 changes: 18 additions & 24 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import functools
import itertools
from numbers import Integral

import numpy as np
Expand Down Expand Up @@ -826,6 +827,17 @@ def __init__(self, ax, *args,
# well. Must ensure allkinds can be zipped below.
self.allkinds = [None] * len(self.allsegs)

# Each entry in (allsegs, allkinds) is a list of (segs, kinds) which
# specifies a list of Paths: segs is a list of (N, 2) arrays of xy
# coordinates, kinds is a list of arrays of corresponding pathcodes.
# However, kinds can also be None; in which case all paths in that list
# are codeless.
allpaths = [
[*map(mpath.Path,
segs,
kinds if kinds is not None else itertools.repeat(None))]
for segs, kinds in zip(self.allsegs, self.allkinds)]

if self.filled:
if self.linewidths is not None:
_api.warn_external('linewidths is ignored by contourf')
Expand All @@ -836,14 +848,14 @@ def __init__(self, ax, *args,

self.collections[:] = [
mcoll.PathCollection(
self._make_paths(segs, kinds),
paths,
antialiaseds=(self.antialiased,),
edgecolors='none',
alpha=self.alpha,
transform=self.get_transform(),
zorder=self._contour_zorder)
for level, level_upper, segs, kinds
in zip(lowers, uppers, self.allsegs, self.allkinds)]
for level, level_upper, paths
in zip(lowers, uppers, allpaths)]
else:
self.tlinewidths = tlinewidths = self._process_linewidths()
tlinestyles = self._process_linestyles()
Expand All @@ -856,7 +868,7 @@ def __init__(self, ax, *args,

self.collections[:] = [
mcoll.PathCollection(
self._make_paths(segs, kinds),
paths,
facecolors="none",
antialiaseds=aa,
linewidths=width,
Expand All @@ -865,9 +877,8 @@ def __init__(self, ax, *args,
transform=self.get_transform(),
zorder=self._contour_zorder,
label='_nolegend_')
for level, width, lstyle, segs, kinds
in zip(self.levels, tlinewidths, tlinestyles, self.allsegs,
self.allkinds)]
for level, width, lstyle, paths
in zip(self.levels, tlinewidths, tlinestyles, allpaths)]

for col in self.collections:
self.axes.add_collection(col, autolim=False)
Expand Down Expand Up @@ -1029,23 +1040,6 @@ def _get_lowers_and_uppers(self):
uppers = self._levels[1:]
return (lowers, uppers)

def _make_paths(self, segs, kinds):
"""
Create and return Path objects for the specified segments and optional
kind codes. *segs* is a list of numpy arrays, each array is either a
closed line loop or open line strip of 2D points with a shape of
(npoints, 2). *kinds* is either None or a list (with the same length
as *segs*) of numpy arrays, each array is of shape (npoints,) and
contains the kind codes for the corresponding line in *segs*. If
*kinds* is None then the Path constructor creates the kind codes
assuming that the line is an open strip.
"""
if kinds is None:
return [mpath.Path(seg) for seg in segs]
else:
return [mpath.Path(seg, codes=kind) for seg, kind
in zip(segs, kinds)]

def changed(self):
if not hasattr(self, "cvalues"):
# Just return after calling the super() changed function
Expand Down