def draw(self, renderer): #xs3d, ys3d, zs3d = self._verts3d for coords in self._verts3d: xs3d, ys3d, zs3d = coords[0], coords[1], coords[2] xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): with warnings.catch_warnings(): warnings.simplefilter("ignore") xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): """ :param renderer: """ xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): """ Draw the axis line. 1) transform the path to the display cooridnate. 2) extend the path to make a room for arrow 3) update the path of the FancyArrowPatch. 4) draw """ path_in_disp = self._line_transform.transform_path(self._line_path) mutation_size = self.get_mutation_scale() #line_mutation_scale() extented_path = self._extend_path(path_in_disp, mutation_size=mutation_size) self._path_original = extented_path FancyArrowPatch.draw(self, renderer)
def draw(self, renderer, rasterized=True): """ Drawing actually happens here """ # Draws only when the dragging finished if self.leftdown: return xs3d, ys3d, zs3d = self._verts3d for i in xrange(len(xs3d)): xs, ys, _ = proj3d.proj_transform(xs3d[i], ys3d[i], zs3d[i], renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) self.set_color(self.colors[i]) FancyArrowPatch.draw(self, renderer) self.leftdown = False
def draw(self, renderer): """Starts as 2-d,g ets projected into 3-d""" xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0],ys[0]),(xs[1],ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): x3d, y3d, z3d = self._verts3d x, y, z = proj3d.proj_transform(x3d, y3d, z3d, renderer.M) self.set_positions((x[0], y[0]), (x[1], y[1])) FancyArrowPatch.draw(self, renderer)
class AnnotationBbox(martist.Artist, _AnnotationBase): """ Annotation-like class, but with offsetbox instead of Text. """ zorder = 3 def __str__(self): return "AnnotationBbox(%g,%g)"%(self.xy[0],self.xy[1]) @docstring.dedent_interpd def __init__(self, offsetbox, xy, xybox=None, xycoords='data', boxcoords=None, frameon=True, pad=0.4, # BboxPatch annotation_clip=None, box_alignment=(0.5, 0.5), bboxprops=None, arrowprops=None, fontsize=None, **kwargs): """ *offsetbox* : OffsetBox instance *xycoords* : same as Annotation but can be a tuple of two strings which are interpreted as x and y coordinates. *boxcoords* : similar to textcoords as Annotation but can be a tuple of two strings which are interpreted as x and y coordinates. *box_alignment* : a tuple of two floats for a vertical and horizontal alignment of the offset box w.r.t. the *boxcoords*. The lower-left corner is (0.0) and upper-right corner is (1.1). other parameters are identical to that of Annotation. """ self.offsetbox = offsetbox self.arrowprops = arrowprops self.set_fontsize(fontsize) if arrowprops is not None: self._arrow_relpos = self.arrowprops.pop("relpos", (0.5, 0.5)) self.arrow_patch = FancyArrowPatch((0, 0), (1,1), **self.arrowprops) else: self._arrow_relpos = None self.arrow_patch = None _AnnotationBase.__init__(self, xy, xytext=xybox, xycoords=xycoords, textcoords=boxcoords, annotation_clip=annotation_clip) martist.Artist.__init__(self, **kwargs) #self._fw, self._fh = 0., 0. # for alignment self._box_alignment = box_alignment # frame self.patch = FancyBboxPatch( xy=(0.0, 0.0), width=1., height=1., facecolor='w', edgecolor='k', mutation_scale=self.prop.get_size_in_points(), snap=True ) self.patch.set_boxstyle("square",pad=pad) if bboxprops: self.patch.set(**bboxprops) self._drawFrame = frameon def contains(self,event): t,tinfo = self.offsetbox.contains(event) #if self.arrow_patch is not None: # a,ainfo=self.arrow_patch.contains(event) # t = t or a # self.arrow_patch is currently not checked as this can be a line - JJ return t,tinfo def get_children(self): children = [self.offsetbox, self.patch] if self.arrow_patch: children.append(self.arrow_patch) return children def set_figure(self, fig): if self.arrow_patch is not None: self.arrow_patch.set_figure(fig) self.offsetbox.set_figure(fig) martist.Artist.set_figure(self, fig) def set_fontsize(self, s=None): """ set fontsize in points """ if s is None: s = rcParams["legend.fontsize"] self.prop=FontProperties(size=s) def get_fontsize(self, s=None): """ return fontsize in points """ return self.prop.get_size_in_points() def update_positions(self, renderer): "Update the pixel positions of the annotated point and the text." xy_pixel = self._get_position_xy(renderer) self._update_position_xybox(renderer, xy_pixel) mutation_scale = renderer.points_to_pixels(self.get_fontsize()) self.patch.set_mutation_scale(mutation_scale) if self.arrow_patch: self.arrow_patch.set_mutation_scale(mutation_scale) def _update_position_xybox(self, renderer, xy_pixel): "Update the pixel positions of the annotation text and the arrow patch." x, y = self.xytext if isinstance(self.textcoords, tuple): xcoord, ycoord = self.textcoords x1, y1 = self._get_xy(renderer, x, y, xcoord) x2, y2 = self._get_xy(renderer, x, y, ycoord) ox0, oy0 = x1, y2 else: ox0, oy0 = self._get_xy(renderer, x, y, self.textcoords) w, h, xd, yd = self.offsetbox.get_extent(renderer) _fw, _fh = self._box_alignment self.offsetbox.set_offset((ox0-_fw*w+xd, oy0-_fh*h+yd)) # update patch position bbox = self.offsetbox.get_window_extent(renderer) #self.offsetbox.set_offset((ox0-_fw*w, oy0-_fh*h)) self.patch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height) x, y = xy_pixel ox1, oy1 = x, y if self.arrowprops: x0, y0 = x, y d = self.arrowprops.copy() # Use FancyArrowPatch if self.arrowprops has "arrowstyle" key. # adjust the starting point of the arrow relative to # the textbox. # TODO : Rotation needs to be accounted. relpos = self._arrow_relpos ox0 = bbox.x0 + bbox.width * relpos[0] oy0 = bbox.y0 + bbox.height * relpos[1] # The arrow will be drawn from (ox0, oy0) to (ox1, # oy1). It will be first clipped by patchA and patchB. # Then it will be shrinked by shirnkA and shrinkB # (in points). If patch A is not set, self.bbox_patch # is used. self.arrow_patch.set_positions((ox0, oy0), (ox1,oy1)) fs = self.prop.get_size_in_points() mutation_scale = d.pop("mutation_scale", fs) mutation_scale = renderer.points_to_pixels(mutation_scale) self.arrow_patch.set_mutation_scale(mutation_scale) patchA = d.pop("patchA", self.patch) self.arrow_patch.set_patchA(patchA) def draw(self, renderer): """ Draw the :class:`Annotation` object to the given *renderer*. """ if renderer is not None: self._renderer = renderer if not self.get_visible(): return xy_pixel = self._get_position_xy(renderer) if not self._check_xy(renderer, xy_pixel): return self.update_positions(renderer) if self.arrow_patch is not None: if self.arrow_patch.figure is None and self.figure is not None: self.arrow_patch.figure = self.figure self.arrow_patch.draw(renderer) if self._drawFrame: self.patch.draw(renderer) self.offsetbox.draw(renderer)
def draw(self, renderer): """Draw the 3D arrow""" xs, ys, zs = proj3d.proj_transform(*self._verts3d, renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xs3d, ys3d, zs3d = zip(*self._segment3d) x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) self.set_positions((x_s[0], y_s[0]), (x_s[1], y_s[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, yd3d, zs3d, renderer.M) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): from mpl_toolkits.mplot3d import proj3d xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xs2d, ys2d = self._verts2d xs, ys = xs2d, ys2d self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xp, yp, zp = self._v x, y, z = proj3d.proj_transform(xp, yp, zp, renderer.M) self.set_positions((x[0], y[0]), (x[1], y[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xs3d, ys3d, zs3d = zip(*self._segment3d) x_s, y_s, _ = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) self._path2d = matplotlib.path.Path(np.column_stack([x_s, y_s])) self.set_positions((x_s[0], y_s[0]), (x_s[1], y_s[1])) FancyArrowPatch.draw(self, renderer)
def draw(self, renderer): xs, ys, zs = proj3d.proj_transform(self.center[0], self.center[1], self.center[2], renderer.M) self.set_positions((0, 0),(xs, ys)) FancyArrowPatch.draw(self, renderer)
def draw(self,renderer): x,y = self._verts self.set_positions((0,0),(x,y)) FancyArrowPatch.draw(self,renderer)
def draw(self, renderer): xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M) self.set_positions((xs[0],ys[0]), (xs[1],ys[1])) FancyArrowPatch.draw(self, renderer)
def do_3d_projection(self, renderer): # renderer arg will be removed in matplotlib==3.6 xs3d, ys3d, zs3d = self._verts3d xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) FancyArrowPatch.draw(self, renderer) return 0
def draw(self, renderer): _xs3d, _ys3d, _zs3d = self._verts3d _xs, _ys, _zs = proj3d.proj_transform(_xs3d, _ys3d, _zs3d, renderer.M) self.set_positions((_xs[0], _ys[0]), (_xs[1], _ys[1])) FancyArrowPatch.draw(self, renderer)
class AnnotationBbox(martist.Artist, _AnnotationBase): """ Annotation-like class, but with offsetbox instead of Text. """ zorder = 3 def __str__(self): return "AnnotationBbox(%g,%g)"%(self.xy[0],self.xy[1]) @docstring.dedent_interpd def __init__(self, offsetbox, xy, xybox=None, xycoords='data', boxcoords=None, frameon=True, pad=0.4, # BboxPatch annotation_clip=None, box_alignment=(0.5, 0.5), bboxprops=None, arrowprops=None, fontsize=None, **kwargs): """ *offsetbox* : OffsetBox instance *xycoords* : same as Annotation but can be a tuple of two strings which are interpreted as x and y coordinates. *boxcoords* : similar to textcoords as Annotation but can be a tuple of two strings which are interpreted as x and y coordinates. *box_alignment* : a tuple of two floats for a vertical and horizontal alignment of the offset box w.r.t. the *boxcoords*. The lower-left corner is (0.0) and upper-right corner is (1.1). other parameters are identical to that of Annotation. """ self.offsetbox = offsetbox self.arrowprops = arrowprops self.set_fontsize(fontsize) if arrowprops is not None: self._arrow_relpos = self.arrowprops.pop("relpos", (0.5, 0.5)) self.arrow_patch = FancyArrowPatch((0, 0), (1,1), **self.arrowprops) else: self._arrow_relpos = None self.arrow_patch = None _AnnotationBase.__init__(self, xy, xytext=xybox, xycoords=xycoords, textcoords=boxcoords, annotation_clip=annotation_clip) martist.Artist.__init__(self, **kwargs) #self._fw, self._fh = 0., 0. # for alignment self._box_alignment = box_alignment # frame self.patch = FancyBboxPatch( xy=(0.0, 0.0), width=1., height=1., facecolor='w', edgecolor='k', mutation_scale=self.prop.get_size_in_points(), snap=True ) self.patch.set_boxstyle("square",pad=pad) if bboxprops: self.patch.set(**bboxprops) self._drawFrame = frameon def contains(self,event): t,tinfo = self.offsetbox.contains(event) #if self.arrow_patch is not None: # a,ainfo=self.arrow_patch.contains(event) # t = t or a # self.arrow_patch is currently not checked as this can be a line - JJ return t,tinfo def get_children(self): children = [self.offsetbox, self.patch] if self.arrow_patch: children.append(self.arrow_patch) return children def set_figure(self, fig): if self.arrow_patch is not None: self.arrow_patch.set_figure(fig) self.offsetbox.set_figure(fig) martist.Artist.set_figure(self, fig) def set_fontsize(self, s=None): """ set fontsize in points """ if s is None: s = rcParams["legend.fontsize"] self.prop=FontProperties(size=s) def get_fontsize(self, s=None): """ return fontsize in points """ return self.prop.get_size_in_points() def update_positions(self, renderer): "Update the pixel positions of the annotated point and the text." xy_pixel = self._get_position_xy(renderer) self._update_position_xybox(renderer, xy_pixel) mutation_scale = renderer.points_to_pixels(self.get_fontsize()) self.patch.set_mutation_scale(mutation_scale) if self.arrow_patch: self.arrow_patch.set_mutation_scale(mutation_scale) def _update_position_xybox(self, renderer, xy_pixel): "Update the pixel positions of the annotation text and the arrow patch." x, y = self.xytext if isinstance(self.textcoords, tuple): xcoord, ycoord = self.textcoords x1, y1 = self._get_xy(renderer, x, y, xcoord) x2, y2 = self._get_xy(renderer, x, y, ycoord) ox0, oy0 = x1, y2 else: ox0, oy0 = self._get_xy(renderer, x, y, self.textcoords) w, h, xd, yd = self.offsetbox.get_extent(renderer) _fw, _fh = self._box_alignment self.offsetbox.set_offset((ox0-_fw*w+xd, oy0-_fh*h+yd)) # update patch position bbox = self.offsetbox.get_window_extent(renderer) #self.offsetbox.set_offset((ox0-_fw*w, oy0-_fh*h)) self.patch.set_bounds(bbox.x0, bbox.y0, bbox.width, bbox.height) x, y = xy_pixel ox1, oy1 = x, y if self.arrowprops: x0, y0 = x, y d = self.arrowprops.copy() # Use FancyArrowPatch if self.arrowprops has "arrowstyle" key. # adjust the starting point of the arrow relative to # the textbox. # TODO : Rotation needs to be accounted. relpos = self._arrow_relpos ox0 = bbox.x0 + bbox.width * relpos[0] oy0 = bbox.y0 + bbox.height * relpos[1] # The arrow will be drawn from (ox0, oy0) to (ox1, # oy1). It will be first clipped by patchA and patchB. # Then it will be shrinked by shirnkA and shrinkB # (in points). If patch A is not set, self.bbox_patch # is used. self.arrow_patch.set_positions((ox0, oy0), (ox1,oy1)) fs = self.prop.get_size_in_points() mutation_scale = d.pop("mutation_scale", fs) mutation_scale = renderer.points_to_pixels(mutation_scale) self.arrow_patch.set_mutation_scale(mutation_scale) patchA = d.pop("patchA", self.patch) self.arrow_patch.set_patchA(patchA) def draw(self, renderer): """ Draw the :class:`Annotation` object to the given *renderer*. """ if renderer is not None: self._renderer = renderer if not self.get_visible(): return xy_pixel = self._get_position_xy(renderer) if not self._check_xy(renderer, xy_pixel): return self.update_positions(renderer) if self.arrow_patch is not None: if self.arrow_patch.figure is None and self.figure is not None: self.arrow_patch.figure = self.figure self.arrow_patch.draw(renderer) if self._drawFrame: self.patch.draw(renderer) self.offsetbox.draw(renderer)
def draw(self,renderer): xp,yp,zp = proj3d.proj_transform(*self.verts,M=renderer.M) self.set_positions((xp[0],yp[0]),(xp[1],yp[1])) FancyArrowPatch.draw(self,renderer)