Esempio n. 1
0
    def artist_overlaps_labels(self, artist: plt.Artist) -> bool:
        renderer = self._ax.figure.canvas.get_renderer()
        artist_box = artist.get_window_extent(renderer)

        for box in (label.get_window_extent(renderer) for label in self._labels):
            if box.overlaps(artist_box):
                return True

        return False
Esempio n. 2
0
    def get_artist_bbox(self, artist: plt.Artist) -> Optional[Bbox]:
        """Attempts to obtain the rectangular coordinates from an artist"""

        ax = artist.axes
        rr = ax.figure.canvas.renderer

        if hasattr(artist, "get_window_extent") \
                and np.any(artist.get_window_extent(rr)) \
                and np.isfinite(artist.get_window_extent(rr)).all():
            box = artist.get_window_extent(rr)
        elif hasattr(artist, "get_tightbbox") and artist.get_tightbbox(rr) is not None:
            box = artist.get_tightbbox(rr)
        elif hasattr(artist, "clipbox") and artist.clipbox is not None:
            box = artist.clipbox
        else:
            print("Couldn't obtain a Bbox for this artist.")
            return

        return box
Esempio n. 3
0
def _position_above(artist: Artist) -> Tuple[float, float]:
    xy = artist.get_xy()
    x = xy[:,0]
    y = xy[:,1]
    return 0.5*(np.min(x) + np.max(x)), np.max(y)
Esempio n. 4
0
def _position_above(artist: Artist) -> Tuple[float, float]:
    xy = artist.get_xy()
    x = xy[:, 0]
    y = xy[:, 1]
    return 0.5 * (np.min(x) + np.max(x)), np.max(y)