Skip to content

Commit a260058

Browse files
committed
Merge pull request #6497 from anntzer/fix-line2d-contains-drawstyle
FIX: Line2D._path obeys drawstyle.
2 parents 77c23f8 + b8fe72c commit a260058

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

lib/matplotlib/cbook.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,12 +2403,14 @@ def pts_to_midstep(x, *args):
24032403
# convert 2D array back to tuple
24042404
return tuple(steps)
24052405

2406-
STEP_LOOKUP_MAP = {'pre': pts_to_prestep,
2406+
STEP_LOOKUP_MAP = {'default': lambda x, y: (x, y),
2407+
'pre': pts_to_prestep,
24072408
'post': pts_to_poststep,
24082409
'mid': pts_to_midstep,
2409-
'step-pre': pts_to_prestep,
2410-
'step-post': pts_to_poststep,
2411-
'step-mid': pts_to_midstep}
2410+
'steps': pts_to_prestep,
2411+
'steps-pre': pts_to_prestep,
2412+
'steps-post': pts_to_poststep,
2413+
'steps-mid': pts_to_midstep}
24122414

24132415

24142416
def index_of(y):

lib/matplotlib/lines.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from . import artist, colors as mcolors
1818
from .artist import Artist
1919
from .cbook import (iterable, is_string_like, is_numlike, ls_mapper_r,
20-
pts_to_prestep, pts_to_poststep, pts_to_midstep)
20+
STEP_LOOKUP_MAP)
2121

2222
from .path import Path
2323
from .transforms import Bbox, TransformedPath, IdentityTransform
@@ -237,6 +237,7 @@ class Line2D(Artist):
237237
'steps': '_draw_steps_pre',
238238
}
239239

240+
# drawStyles should now be deprecated.
240241
drawStyles = {}
241242
drawStyles.update(_drawStyles_l)
242243
drawStyles.update(_drawStyles_s)
@@ -470,8 +471,7 @@ def contains(self, mouseevent):
470471
# application has set the error flags such that an exception is raised
471472
# on overflow, we temporarily set the appropriate error flags here and
472473
# set them back when we are finished.
473-
olderrflags = np.seterr(all='ignore')
474-
try:
474+
with np.errstate(all='ignore'):
475475
# Check for collision
476476
if self._linestyle in ['None', None]:
477477
# If no line, return the nearby point(s)
@@ -480,20 +480,9 @@ def contains(self, mouseevent):
480480
else:
481481
# If line, return the nearby segment(s)
482482
ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
483-
finally:
484-
np.seterr(**olderrflags)
485483

486484
ind += self.ind_offset
487485

488-
# Debugging message
489-
if False and self._label != '':
490-
print("Checking line", self._label,
491-
"at", mouseevent.x, mouseevent.y)
492-
print('xt', xt)
493-
print('yt', yt)
494-
#print 'dx,dy', (xt-mouseevent.x)**2., (yt-mouseevent.y)**2.
495-
print('ind', ind)
496-
497486
# Return the point(s) within radius
498487
return len(ind) > 0, dict(ind=ind)
499488

@@ -691,7 +680,8 @@ def recache(self, always=False):
691680
interpolation_steps = self._path._interpolation_steps
692681
else:
693682
interpolation_steps = 1
694-
self._path = Path(self._xy, None, interpolation_steps)
683+
xy = STEP_LOOKUP_MAP[self._drawstyle](*self._xy.T)
684+
self._path = Path(np.asarray(xy).T, None, interpolation_steps)
695685
self._transformed_path = None
696686
self._invalidx = False
697687
self._invalidy = False
@@ -764,8 +754,6 @@ def draw(self, renderer):
764754
tpath, affine = transf_path.get_transformed_path_and_affine()
765755
if len(tpath.vertices):
766756
self._lineFunc = getattr(self, funcname)
767-
funcname = self.drawStyles.get(self._drawstyle, '_draw_lines')
768-
drawFunc = getattr(self, funcname)
769757
gc = renderer.new_gc()
770758
self._set_gc_clip(gc)
771759

@@ -788,7 +776,7 @@ def draw(self, renderer):
788776
if self.get_sketch_params() is not None:
789777
gc.set_sketch_params(*self.get_sketch_params())
790778

791-
drawFunc(renderer, gc, tpath, affine.frozen())
779+
self._draw_lines(renderer, gc, tpath, affine.frozen())
792780
gc.restore()
793781

794782
if self._marker and self._markersize > 0:
@@ -1234,27 +1222,6 @@ def set_dashes(self, seq):
12341222
def _draw_lines(self, renderer, gc, path, trans):
12351223
self._lineFunc(renderer, gc, path, trans)
12361224

1237-
def _draw_steps_pre(self, renderer, gc, path, trans):
1238-
steps = np.vstack(pts_to_prestep(*self._xy.T)).T
1239-
1240-
path = Path(steps)
1241-
path = path.transformed(self.get_transform())
1242-
self._lineFunc(renderer, gc, path, IdentityTransform())
1243-
1244-
def _draw_steps_post(self, renderer, gc, path, trans):
1245-
steps = np.vstack(pts_to_poststep(*self._xy.T)).T
1246-
1247-
path = Path(steps)
1248-
path = path.transformed(self.get_transform())
1249-
self._lineFunc(renderer, gc, path, IdentityTransform())
1250-
1251-
def _draw_steps_mid(self, renderer, gc, path, trans):
1252-
steps = np.vstack(pts_to_midstep(*self._xy.T)).T
1253-
1254-
path = Path(steps)
1255-
path = path.transformed(self.get_transform())
1256-
self._lineFunc(renderer, gc, path, IdentityTransform())
1257-
12581225
def _draw_solid(self, renderer, gc, path, trans):
12591226
gc.set_linestyle('solid')
12601227
renderer.draw_path(gc, path, trans)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy