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

Skip to content

Commit 97f2650

Browse files
committed
Use transformed paths for contour labelling decisions
1 parent 2c45571 commit 97f2650

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/matplotlib/contour.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def _split_path_and_get_label_rotation(self, path, idx, screen_pos, lw, spacing=
322322
Parameters
323323
----------
324324
path : Path
325-
The path where the label will be inserted, in data space.
325+
The path where the label will be inserted, in screen space.
326326
idx : int
327327
The vertex index after which the label will be inserted.
328328
screen_pos : (float, float)
@@ -352,7 +352,7 @@ def _split_path_and_get_label_rotation(self, path, idx, screen_pos, lw, spacing=
352352
if hasattr(self, "_old_style_split_collections"):
353353
del self._old_style_split_collections # Invalidate them.
354354

355-
xys = path.vertices
355+
xys = self.get_transform().inverted().transform(path.vertices)
356356
codes = path.codes
357357

358358
# Insert a vertex at idx/pos (converting back to data space), if there isn't yet
@@ -582,7 +582,8 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
582582

583583
idx_level_min, idx_vtx_min, proj = self._find_nearest_contour(
584584
(x, y), self.labelIndiceList)
585-
path = self._paths[idx_level_min]
585+
path = self.get_transform().transform_path(self._paths[idx_level_min])
586+
586587
level = self.labelIndiceList.index(idx_level_min)
587588
label_width = self._get_nth_label_width(level)
588589
rotation, path = self._split_path_and_get_label_rotation(
@@ -614,8 +615,9 @@ def labels(self, inline, inline_spacing):
614615
trans = self.get_transform()
615616
label_width = self._get_nth_label_width(idx)
616617
additions = []
617-
for subpath in self._paths[icon]._iter_connected_components():
618-
screen_xys = trans.transform(subpath.vertices)
618+
for subpath in trans.transform_path(
619+
self._paths[icon])._iter_connected_components():
620+
screen_xys = subpath.vertices
619621
# Check if long enough for a label
620622
if self.print_label(screen_xys, label_width):
621623
x, y, idx = self.locate_label(screen_xys, label_width)
@@ -626,7 +628,7 @@ def labels(self, inline, inline_spacing):
626628
if inline: # If inline, add new contours
627629
additions.append(path)
628630
else: # If not adding label, keep old path
629-
additions.append(subpath)
631+
additions.append(trans.inverted().transform_path(subpath))
630632
# After looping over all segments on a contour, replace old path by new one
631633
# if inlining.
632634
if inline:

0 commit comments

Comments
 (0)