def assert_no_legend_overlap(self, message="Legends overlap eachother"): """When multiple legends on ax, asserts that there are no two legends in ax that overlap each other Parameters ---------- message : string The error message to be displayed if two legends overlap. Raises ------- AssertionError with message `m` if legends overlap """ legends = self.get_legends() n = len(legends) for i in range(n - 1): # Get extent of first legend in check, RendererBase() avoids error leg_extent1 = (legends[i].get_window_extent( RendererBase()).get_points()) for j in range(i + 1, n): # Get extent of second legend in check leg_extent2 = (legends[j].get_window_extent( RendererBase()).get_points()) assert not self.legends_overlap(leg_extent1, leg_extent2), message
def assert_legend_no_overlay_content(self, message="Legend overlays plot window" ): """Asserts that each legend does not overlay plot window Parameters ---------- message : string The error message to be displayed if the legend overlays the plot window. Raises ------- AssertionError with message `m` if legend does not overlay plot window """ # RendererBase() is needed to get extent, otherwise raises an error plot_extent = self.ax.get_window_extent(RendererBase()).get_points() legends = self.get_legends() for leg in legends: # RendererBase() is needed to get extent, otherwise raises error leg_extent = leg.get_window_extent(RendererBase()).get_points() legend_left = leg_extent[1][0] < plot_extent[0][0] legend_right = leg_extent[0][0] > plot_extent[1][0] legend_below = leg_extent[1][1] < plot_extent[0][1] assert legend_left or legend_right or legend_below, message
def assert_no_legend_overlap(self, m="Legends overlap eachother"): """When multiple legends on ax, asserts that there are no two legends in ax that overlap each other Parameters ---------- m: string error message if assertion is not met Returns ------- Nothing (if checks pass) or prints error message m """ legends = self.get_legends() n = len(legends) for i in range(n - 1): # Get extent of first legend in check, RendererBase() avoids error leg_extent1 = ( legends[i].get_window_extent(RendererBase()).get_points() ) for j in range(i + 1, n): # Get extent of second legend in check leg_extent2 = ( legends[j].get_window_extent(RendererBase()).get_points() ) assert ( self.legends_overlap(leg_extent1, leg_extent2) == False ), m
def assert_legend_no_overlay_content( self, m="Legend overlays plot window" ): """Asserts that each legend does not overlay plot window Parameters ---------- m: string error message if assertion is not met Returns ------- Nothing (if checks pass) or prints error message m """ # RendererBase() is needed to get extent, otherwise raises an error plot_extent = self.ax.get_window_extent(RendererBase()).get_points() legends = self.get_legends() for leg in legends: # RendererBase() is needed to get extent, otherwise raises error leg_extent = leg.get_window_extent(RendererBase()).get_points() legend_left = leg_extent[1][0] < plot_extent[0][0] legend_right = leg_extent[0][0] > plot_extent[1][0] legend_below = leg_extent[1][1] < plot_extent[0][1] assert legend_left or legend_right or legend_below, m
def _format_scalarmappable_value(artist, idx): # matplotlib/matplotlib#12473. data = artist.get_array()[idx] if np.ndim(data) == 0: if not artist.colorbar: fig = Figure() ax = fig.subplots() artist.colorbar = fig.colorbar(artist, cax=ax) # This hack updates the ticks without actually paying the cost of # drawing (RendererBase.draw_path raises NotImplementedError). try: ax.yaxis.draw(RendererBase()) except NotImplementedError: pass fmt = artist.colorbar.formatter.format_data_short return "[" + _strip_math(fmt(data).strip()) + "]" else: return artist.format_cursor_data(data) # Includes brackets.
def check(master_transform, paths, all_transforms, offsets, facecolors, edgecolors): rb = RendererBase() raw_paths = list(rb._iter_collection_raw_paths( master_transform, paths, all_transforms)) gc = rb.new_gc() ids = [path_id for xo, yo, path_id, gc0, rgbFace in rb._iter_collection(gc, master_transform, all_transforms, range(len(raw_paths)), offsets, transforms.IdentityTransform(), facecolors, edgecolors, [], [], [False], [], 'data')] uses = rb._iter_collection_uses_per_path( paths, all_transforms, offsets, facecolors, edgecolors) if raw_paths: seen = np.bincount(ids, minlength=len(raw_paths)) assert set(seen).issubset([uses - 1, uses])
def check(master_transform, paths, all_transforms, offsets, facecolors, edgecolors): rb = RendererBase() raw_paths = list(rb._iter_collection_raw_paths( master_transform, paths, all_transforms)) gc = rb.new_gc() ids = [path_id for xo, yo, path_id, gc0, rgbFace in rb._iter_collection(gc, master_transform, all_transforms, range(len(raw_paths)), offsets, transforms.IdentityTransform(), facecolors, edgecolors, [], [], [False], [], 'data')] uses = rb._iter_collection_uses_per_path( paths, all_transforms, offsets, facecolors, edgecolors) seen = [0] * len(raw_paths) for i in ids: seen[i] += 1 for n in seen: assert n in (uses-1, uses)