Example #1
0
    def finalize_offset(self):
        loc_in_canvas = self.get_loc_in_canvas()

        bbox = self.legend.get_bbox_to_anchor()
        _bbox_transform = BboxTransformFrom(bbox)
        self.legend._loc = tuple(
            _bbox_transform.transform_point(loc_in_canvas))
Example #2
0
 def _update_loc(self, loc_in_canvas):
     bbox = self.legend.get_bbox_to_anchor()
     # if bbox has zero width or height, the transformation is
     # ill-defined. Fall back to the default bbox_to_anchor.
     if bbox.width == 0 or bbox.height == 0:
         self.legend.set_bbox_to_anchor(None)
         bbox = self.legend.get_bbox_to_anchor()
     _bbox_transform = BboxTransformFrom(bbox)
     self.legend._loc = tuple(_bbox_transform.transform(loc_in_canvas))
Example #3
0
    def _update_loc(self, loc_in_canvas):
        bbox = self.legend.get_bbox_to_anchor()

        # if bbox has zero width or height, the transformation is
        # ill-defined. Fall back to the defaul bbox_to_anchor.
        if bbox.width ==0 or bbox.height ==0:
            self.legend.set_bbox_to_anchor(None)
            bbox = self.legend.get_bbox_to_anchor()

        _bbox_transform = BboxTransformFrom(bbox)
        self.legend._loc = tuple(_bbox_transform.transform_point(loc_in_canvas))
Example #4
0
    def finalize_offset(self):
        loc_in_canvas = self.get_loc_in_canvas()

        bbox = self.legend.get_bbox_to_anchor()

        # if bbox has zero width or height, the transformation is
        # ill-defined. Fall back to the defaul bbox_to_anchor.
        if bbox.width == 0 or bbox.height == 0:
            self.legend.set_bbox_to_anchor(None)
            bbox = self.legend.get_bbox_to_anchor()

        _bbox_transform = BboxTransformFrom(bbox)
        self.legend._loc = tuple(
            _bbox_transform.transform_point(loc_in_canvas))
    def get_transform(self):

        # If we don't override this, the transform includes LogTransforms
        # and the final image gets warped to be 'correct' in data space
        # since Matplotlib 2.x:
        #
        #   https://matplotlib.org/users/prev_whats_new/whats_new_2.0.0.html#non-linear-scales-on-image-plots
        #
        # However, we want pixels to always visually be the same size, so we
        # override the transform to not include the LogTransform components.

        xmin, xmax = self._ax.get_xlim()
        ymin, ymax = self._ax.get_ylim()

        bbox = BboxTransformFrom(TransformedBbox(Bbox([[xmin, ymin], [xmax, ymax]]),
                                                 IDENTITY))

        return bbox + self._ax.transAxes
Example #6
0
    def create_artists(self, legend, orig_handle, xdescent, ydescent, width,
                       height, fontsize, trans):

        legline, _ = HandlerLine2D.create_artists(self, legend, orig_handle,
                                                  xdescent, ydescent, width,
                                                  height, fontsize, trans)

        legline.set_data(*orig_handle.get_data())

        ext = mpath.get_paths_extents([orig_handle.get_path()])
        if ext.width == 0:
            ext.x0 -= 0.1
            ext.x1 += 0.1
        bbox0 = BboxTransformFrom(ext)
        bbox1 = BboxTransformTo(
            Bbox.from_bounds(xdescent, ydescent, width, height))

        legline.set_transform(bbox0 + bbox1 + trans)
        return legline,
Example #7
0
    def __init__(self, object=None, anchor='bl', spacing=12):

        if isinstance(object, plt.Figure):
            fig = object
        elif hasattr(object, 'figure'):
            fig = object.figure
        else:
            raise Exception('Cannot find figure from object')

        self.obj = object
        self.fig = fig
        self.spacing = spacing
        self.anchor = anchor

        self.fig_pos = fig.bbox._points
        self.obj_pos = self.get_object_position()

        bbox = self.get_bbox()
        super().__init__(BboxTransformFrom(bbox), self.fig.transFigure)
Example #8
0
 def finalize_offset(self):
     loc_in_canvas = self.get_loc_in_canvas()
     bbox = self.legend.get_bbox_to_anchor()
     _bbox_transform = BboxTransformFrom(bbox)
     self.legend._loc = tuple(_bbox_transform.transform_point(loc_in_canvas))