8000 Speed up quadmesh drawing. · matplotlib/matplotlib@c7837e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit c7837e4

Browse files
committed
Speed up quadmesh drawing.
svn path=/trunk/matplotlib/; revision=6350
1 parent ac2da58 commit c7837e4

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/matplotlib/collections.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,6 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
551551
else:
552552
c = coordinates
553553

554-
# We could let the Path constructor generate the codes for us,
555-
# but this is faster, since we know they'll always be the same
556-
codes = np.array(
557-
[Path.MOVETO, Path.LINETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY],
558-
Path.code_type)
559-
560554
points = np.concatenate((
561555
c[0:-1, 0:-1],
562556
c[0:-1, 1: ],
@@ -565,7 +559,7 @@ def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
565559
c[0:-1, 0:-1]
566560
), axis=2)
567561
points = points.reshape((meshWidth * meshHeight, 5, 2))
568-
return [Path(x, codes) for x in points]
562+
return [Path(x) for x in points]
569563
convert_mesh_to_paths = staticmethod(convert_mesh_to_paths)
570564

571565
def get_datalim(self, transData):

lib/matplotlib/path.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def __init__(self, vertices, codes=None):
111111

112112
self.should_simplify = (len(vertices) >= 128 and
113113
(codes is None or np.all(codes <= Path.LINETO)))
114+
self.has_nonfinite = not np.isfinite(vertices).all()
114115
self.codes = codes
115116
self.vertices = vertices
116117

@@ -183,13 +184,18 @@ def iter_segments(self, simplify=None):
183184
for v in vertices[1:]:
184185
yield v, LINETO
185186
elif codes is None:
186-
next_code = MOVETO
187-
for v in vertices:
188-
if (~isfinite(v)).any():
189-
next_code = MOVETO
190-
else:
191-
yield v, next_code
192-
next_code = LINETO
187+
if self.has_nonfinite:
188+
next_code = MOVETO
189+
for v in vertices:
190+
if np.isfinite(v).all():
191+
yield v, next_code
192+
next_code = LINETO
193+
else:
194+
next_code = MOVETO
195+
else:
196+
yield vertices[0], MOVETO
197+
for v in vertices[1:]:
198+
yield v, LINETO
193199
else:
194200
i = 0
195201
was_nan = False
@@ -203,7 +209,7 @@ def iter_segments(self, simplify=None):
203209
else:
204210
num_vertices = NUM_VERTICES[int(code)]
205211
curr_vertices = vertices[i:i+num_vertices].flatten()
206-
if (~isfinite(curr_vertices)).any():
212+
if not isfinite(curr_vertices).all():
207213
was_nan = True
208214
elif was_nan:
209215
yield curr_vertices[-2:], MOVETO

0 commit comments

Comments
 (0)
0