File tree Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +31
-9
lines changed
Original file line number Diff line number Diff line change @@ -1392,15 +1392,18 @@ def _find_nearest_contour(self, xy, indices=None):
1392
1392
1393
1393
for idx_level in indices :
1394
1394
path = self ._paths [idx_level ]
1395
- if not len (path .vertices ):
1396
- continue
1397
- lc = self .get_transform ().transform (path .vertices )
1398
- d2 , proj , leg = _find_closest_point_on_path (lc , xy )
1399
- if d2 < d2min :
1400
- d2min = d2
1401
- idx_level_min = idx_level
1402
- idx_vtx_min = leg [1 ]
1403
- proj_min = proj
1395
+ idx_vtx_start = 0
1396
+ for subpath in path ._iter_connected_components ():
1397
+ if not len (subpath .vertices ):
1398
+ continue
1399
+ lc = self .get_transform ().transform (subpath .vertices )
1400
+ d2 , proj , leg = _find_closest_point_on_path (lc , xy )
1401
+ if d2 < d2min :
1402
+ d2min = d2
1403
+ idx_level_min = idx_level
1404
+ idx_vtx_min = leg [1 ] + idx_vtx_start
1405
+ proj_min = proj
1406
+ idx_vtx_start += len (subpath )
1404
1407
1405
1408
return idx_level_min , idx_vtx_min , proj_min
1406
1409
Original file line number Diff line number Diff line change @@ -125,6 +125,25 @@ def test_contour_manual_labels(split_collections):
125
125
plt .clabel (cs , manual = pts , fontsize = 'small' , colors = ('r' , 'g' ))
126
126
127
127
128
+ def test_contour_manual_moveto ():
129
+ x = np .linspace (- 10 , 10 )
130
+ y = np .linspace (- 10 , 10 )
131
+
132
+ X , Y = np .meshgrid (x , y )
133
+
134
+ Z = X ** 2 * 1 / Y ** 2 - 1
135
+
136
+ contours = plt .contour (X , Y , Z , levels = [0 , 100 ])
137
+
138
+ # This point lies on the `MOVETO` line for the 100 contour
139
+ # but is actually closest to the 0 contour
140
+ point = (1.3 , 1 )
141
+ clabels = plt .clabel (contours , manual = [point ])
142
+
143
+ # Ensure that the 0 contour was chosen, not the 100 contour
144
+ assert clabels [0 ].get_text () == "0"
145
+
146
+
128
147
@pytest .mark .parametrize ("split_collections" , [False , True ])
129
148
@image_comparison (['contour_disconnected_segments' ],
130
149
remove_text = True , style = 'mpl20' , extensions = ['png' ])
You can’t perform that action at this time.
0 commit comments