|
18 | 18 |
|
19 | 19 | import matplotlib |
20 | 20 | import matplotlib as mpl |
21 | | -from matplotlib import rc_context |
| 21 | +from matplotlib import rc_context, patheffects |
22 | 22 | from matplotlib._api import MatplotlibDeprecationWarning |
23 | 23 | import matplotlib.colors as mcolors |
24 | 24 | import matplotlib.dates as mdates |
@@ -8455,6 +8455,43 @@ def test_zorder_and_explicit_rasterization(): |
8455 | 8455 | fig.savefig(b, format='pdf') |
8456 | 8456 |
|
8457 | 8457 |
|
| 8458 | +@image_comparison(["preset_clip_paths.png"], remove_text=True, style="mpl20") |
| 8459 | +def test_preset_clip_paths(): |
| 8460 | + fig, ax = plt.subplots() |
| 8461 | + |
| 8462 | + poly = mpl.patches.Polygon( |
| 8463 | + [[1, 0], [0, 1], [-1, 0], [0, -1]], facecolor="#ddffdd", |
| 8464 | + edgecolor="#00ff00", linewidth=2, alpha=0.5) |
| 8465 | + |
| 8466 | + ax.add_patch(poly) |
| 8467 | + |
| 8468 | + line = mpl.lines.Line2D((-1, 1), (0.5, 0.5), clip_on=True, clip_path=poly) |
| 8469 | + line.set_path_effects([patheffects.withTickedStroke()]) |
| 8470 | + ax.add_artist(line) |
| 8471 | + |
| 8472 | + line = mpl.lines.Line2D((-1, 1), (-0.5, -0.5), color='r', clip_on=True, |
| 8473 | + clip_path=poly) |
| 8474 | + ax.add_artist(line) |
| 8475 | + |
| 8476 | + poly2 = mpl.patches.Polygon( |
| 8477 | + [[-1, 1], [0, 1], [0, -0.25]], facecolor="#beefc0", alpha=0.3, |
| 8478 | + edgecolor="#faded0", linewidth=2, clip_on=True, clip_path=poly) |
| 8479 | + ax.add_artist(poly2) |
| 8480 | + |
| 8481 | + # When text clipping works, the "Annotation" text should be clipped |
| 8482 | + ax.annotate('Annotation', (-0.75, -0.75), xytext=(0.1, 0.75), |
| 8483 | + arrowprops={'color': 'k'}, clip_on=True, clip_path=poly) |
| 8484 | + |
| 8485 | + poly3 = mpl.patches.Polygon( |
| 8486 | + [[0, 0], [0, 0.5], [0.5, 0.5], [0.5, 0]], facecolor="g", edgecolor="y", |
| 8487 | + linewidth=2, alpha=0.3, clip_on=True, clip_path=poly) |
| 8488 | + |
| 8489 | + fig.add_artist(poly3, clip=True) |
| 8490 | + |
| 8491 | + ax.set_xlim(-1, 1) |
| 8492 | + ax.set_ylim(-1, 1) |
| 8493 | + |
| 8494 | + |
8458 | 8495 | @mpl.style.context('default') |
8459 | 8496 | def test_rc_axes_label_formatting(): |
8460 | 8497 | mpl.rcParams['axes.labelcolor'] = 'red' |
|
0 commit comments