(fig)
| 58 | axs[2].imshow(A, interpolation='bicubic') |
| 59 | |
| 60 | def plot_paths(fig): |
| 61 | # clipping support class, copied from demo_text_path.py gallery example |
| 62 | class PathClippedImagePatch(PathPatch): |
| 63 | """ |
| 64 | The given image is used to draw the face of the patch. Internally, |
| 65 | it uses BboxImage whose clippath set to the path of the patch. |
| 66 | |
| 67 | FIXME : The result is currently dpi dependent. |
| 68 | """ |
| 69 | |
| 70 | def __init__(self, path, bbox_image, **kwargs): |
| 71 | super().__init__(path, **kwargs) |
| 72 | self.bbox_image = BboxImage( |
| 73 | self.get_window_extent, norm=None, origin=None) |
| 74 | self.bbox_image.set_data(bbox_image) |
| 75 | |
| 76 | def set_facecolor(self, color): |
| 77 | """Simply ignore facecolor.""" |
| 78 | super().set_facecolor("none") |
| 79 | |
| 80 | def draw(self, renderer=None): |
| 81 | # the clip path must be updated every draw. any solution? -JJ |
| 82 | self.bbox_image.set_clip_path(self._path, self.get_transform()) |
| 83 | self.bbox_image.draw(renderer) |
| 84 | super().draw(renderer) |
| 85 | |
| 86 | subfigs = fig.subfigures(1, 3) |
| 87 | |
| 88 | # add a polar projection |
| 89 | px = subfigs[0].add_subplot(projection="polar") |
| 90 | pimg = px.imshow([[2]]) |
| 91 | pimg.set_clip_path(Circle((0, 1), radius=0.3333)) |
| 92 | |
| 93 | # add a text-based clipping path (origin: demo_text_path.py) |
| 94 | ax = subfigs[1].add_subplot() |
| 95 | arr = plt.imread(get_sample_data("grace_hopper.jpg")) |
| 96 | text_path = TextPath((0, 0), "!?", size=150) |
| 97 | p = PathClippedImagePatch(text_path, arr, ec="k") |
| 98 | offsetbox = AuxTransformBox(IdentityTransform()) |
| 99 | offsetbox.add_artist(p) |
| 100 | ao = AnchoredOffsetbox(loc='upper left', child=offsetbox, frameon=True, |
| 101 | borderpad=0.2) |
| 102 | ax.add_artist(ao) |
| 103 | |
| 104 | # add a 2x2 grid of path-clipped axes (origin: test_artist.py) |
| 105 | exterior = Path.unit_rectangle().deepcopy() |
| 106 | exterior.vertices *= 4 |
| 107 | exterior.vertices -= 2 |
| 108 | interior = Path.unit_circle().deepcopy() |
| 109 | interior.vertices = interior.vertices[::-1] |
| 110 | clip_path = Path.make_compound_path(exterior, interior) |
| 111 | |
| 112 | star = Path.unit_regular_star(6).deepcopy() |
| 113 | star.vertices *= 2.6 |
| 114 | |
| 115 | (row1, row2) = subfigs[2].subplots(2, 2, sharex=True, sharey=True, |
| 116 | gridspec_kw=dict(hspace=0, wspace=0)) |
| 117 | for row in (row1, row2): |
no test coverage detected
searching dependent graphs…