|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | import matplotlib as mpl |
8 | | -from matplotlib.path import Path |
9 | 8 | from matplotlib.projections.polar import RadialLocator |
10 | 9 | from matplotlib import pyplot as plt |
11 | 10 | from matplotlib.testing.decorators import image_comparison, check_figures_equal |
@@ -329,54 +328,26 @@ def test_polar_gridlines(): |
329 | 328 | assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2 |
330 | 329 |
|
331 | 330 |
|
332 | | -@pytest.mark.parametrize('span_deg', [359.999999, 360.0, |
333 | | - 360 - 1e-9, 720.0]) |
334 | | -def test_polar_transform_constant_r_arc(span_deg): |
335 | | - # PolarTransform's chunking boundary used to disagree with Path.arc's |
336 | | - # angle-unwrap step, so an angular delta of nearly-but-not-exactly |
337 | | - # 360 degrees collapsed to a near-empty arc. Apply the transform to |
338 | | - # a constant-r path of varying angular span and check that the |
339 | | - # result remains a non-degenerate circle. |
| 331 | +@pytest.mark.parametrize('theta_zero_location, theta_offset', [ |
| 332 | + (("N", 20), None), |
| 333 | + (("N", 30), None), |
| 334 | + (None, 1.570796327), |
| 335 | +]) |
| 336 | +def test_polar_outer_spine_not_collapsed(theta_zero_location, theta_offset): |
| 337 | + # The polar outer spine spans a full turn via Path.arc. For some theta |
| 338 | + # offsets/directions, floating-point error left the span just short of a |
| 339 | + # full 360 degrees and the spine collapsed to a near-empty arc. Check it |
| 340 | + # still occupies a sensible area. |
340 | 341 | fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) |
| 342 | + if theta_zero_location is not None: |
| 343 | + ax.set_theta_direction(-1) |
| 344 | + ax.set_theta_zero_location(*theta_zero_location) |
| 345 | + if theta_offset is not None: |
| 346 | + ax.set_theta_offset(theta_offset) |
341 | 347 | fig.canvas.draw() |
342 | | - r = 1.0 |
343 | | - path = Path([(0.0, r), (np.deg2rad(span_deg), r)], |
344 | | - [Path.MOVETO, Path.LINETO]) |
345 | | - path._interpolation_steps = 100 |
346 | | - out = ax.transProjection.transform_path_non_affine(path) |
347 | | - spread = np.ptp(out.vertices, axis=0) |
348 | | - assert spread.min() > r * 1.5, ( |
349 | | - f"transformed arc collapsed for span={span_deg}: spread={spread}") |
350 | | - |
351 | | - |
352 | | -@pytest.mark.parametrize('angle', [10, 20, 30, 45, 90, 110]) |
353 | | -def test_polar_inverted_theta_outer_spine(angle): |
354 | | - # With set_theta_direction(-1) and certain values of |
355 | | - # set_theta_zero_location offset, the polar outer spine used to |
356 | | - # collapse to a near-empty arc. |
357 | | - fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) |
358 | | - ax.set_theta_direction(-1) |
359 | | - ax.set_theta_zero_location("N", angle) |
360 | | - fig.canvas.draw() |
361 | | - spine = ax.spines['polar'] |
362 | | - tpath = spine.get_transform().transform_path(spine.get_path()) |
363 | | - spread = np.ptp(tpath.vertices, axis=0) |
364 | | - assert spread.min() > 50, ( |
365 | | - f"outer spine collapsed for angle={angle}: spread={spread}") |
366 | | - |
367 | | - |
368 | | -@pytest.mark.parametrize('offset', [1.0, np.pi / 2, np.pi, 1.570796327]) |
369 | | -def test_polar_theta_offset_outer_spine(offset): |
370 | | - # set_theta_offset used to remove the outer spine outline; same |
371 | | - # floating-point root cause as the inverted-theta case above. |
372 | | - fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) |
373 | | - ax.set_theta_offset(offset) |
374 | | - fig.canvas.draw() |
375 | | - spine = ax.spines['polar'] |
376 | | - tpath = spine.get_transform().transform_path(spine.get_path()) |
377 | | - spread = np.ptp(tpath.vertices, axis=0) |
378 | | - assert spread.min() > 50, ( |
379 | | - f"outer spine collapsed for theta_offset={offset}: spread={spread}") |
| 348 | + # A collapsed spine has a near-zero (~1e-13) bounding box; a healthy one is |
| 349 | + # hundreds of points across. |
| 350 | + assert ax.spines['polar'].get_tightbbox().size.min() > 1 |
380 | 351 |
|
381 | 352 |
|
382 | 353 | def test_get_tightbbox_polar(): |
|
0 commit comments