| 288 | |
| 289 | |
| 290 | def test_label_contour_start(): |
| 291 | # Set up data and figure/axes that result in automatic labelling adding the |
| 292 | # label to the start of a contour |
| 293 | |
| 294 | _, ax = plt.subplots(dpi=100) |
| 295 | lats = lons = np.linspace(-np.pi / 2, np.pi / 2, 50) |
| 296 | lons, lats = np.meshgrid(lons, lats) |
| 297 | wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons) |
| 298 | mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2) |
| 299 | data = wave + mean |
| 300 | |
| 301 | cs = ax.contour(lons, lats, data) |
| 302 | |
| 303 | with mock.patch.object( |
| 304 | cs, '_split_path_and_get_label_rotation', |
| 305 | wraps=cs._split_path_and_get_label_rotation) as mocked_splitter: |
| 306 | # Smoke test that we can add the labels |
| 307 | cs.clabel(fontsize=9) |
| 308 | |
| 309 | # Verify at least one label was added to the start of a contour. I.e. the |
| 310 | # splitting method was called with idx=0 at least once. |
| 311 | idxs = [cargs[0][1] for cargs in mocked_splitter.call_args_list] |
| 312 | assert 0 in idxs |
| 313 | |
| 314 | |
| 315 | def test_clabel_raises_on_filled_contours(): |