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

Skip to content

Commit 6401e08

Browse files
committed
Add test for disconnected paths, remove invalidated paths
1 parent f0a3a09 commit 6401e08

File tree

5 files changed

+285
-0
lines changed

5 files changed

+285
-0
lines changed

lib/matplotlib/contour.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ def _split_path_and_get_label_rotation(self, path, idx, screen_pos, lw, spacing=
350350
taken into account when breaking the path, but not when computing the angle.
351351
"""
352352
if hasattr(self, "_old_style_split_collections"):
353+
vis = False
354+
for coll in self._old_style_split_collections:
355+
vis |= coll.get_visible()
356+
coll.remove()
357+
self.set_visible(vis)
353358
del self._old_style_split_collections # Invalidate them.
354359

355360
xys = path.vertices
Lines changed: 257 additions & 0 deletions
Loading

lib/matplotlib/tests/test_contour.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,31 @@ def test_contour_manual_labels(split_collections):
116116

117117
plt.figure(figsize=(6, 2), dpi=200)
118118
cs = plt.contour(x, y, z)
119+
120+
_maybe_split_collections(split_collections)
121+
119122
pts = np.array([(1.0, 3.0), (1.0, 4.4), (1.0, 6.0)])
120123
plt.clabel(cs, manual=pts)
121124
pts = np.array([(2.0, 3.0), (2.0, 4.4), (2.0, 6.0)])
122125
plt.clabel(cs, manual=pts, fontsize='small', colors=('r', 'g'))
123126

127+
128+
@pytest.mark.parametrize("split_collections", [False, True])
129+
@image_comparison(['contour_disconnected_segments'],
130+
remove_text=True, style='mpl20', tol=0.26)
131+
def test_contour_label_with_disconnected_segments(split_collections):
132+
x, y = np.mgrid[-1:1:21j, -1:1:21j]
133+
z = 1 / np.sqrt(0.01 + (x + 0.3) ** 2 + y ** 2)
134+
z += 1 / np.sqrt(0.01 + (x - 0.3) ** 2 + y ** 2)
135+
136+
plt.figure()
137+
cs = plt.contour(x, y, z, levels=[7])
138+
139+
# Adding labels should invalidate the old style
140+
_maybe_split_collections(split_collections)
141+
142+
cs.clabel(manual=[(0.2, 0.1)])
143+
124144
_maybe_split_collections(split_collections)
125145

126146

@@ -232,6 +252,9 @@ def test_labels(split_collections):
232252
disp_units = [(216, 177), (359, 290), (521, 406)]
233253
data_units = [(-2, .5), (0, -1.5), (2.8, 1)]
234254

255+
# Adding labels should invalidate the old style
256+
_maybe_split_collections(split_collections)
257+
235258
CS.clabel()
236259

237260
for x, y in data_units:

0 commit comments

Comments
 (0)