def y_tick_label(self, y, size, offset=7, ax=None): """ uses the icon as a ticklabel at location x Args: y (float) the position of the tick size (float) scaling the size of the icon offset (integer) how far the icon should be from the axis in points ax (matplotlib axis) the axis to put the label on """ if ax is None: ax = plt.gca() if self.final_image is not None: imagebox = OffsetImage(self.final_image, zoom=size) ab = AnnotationBbox(imagebox, (0, y), xybox=(-offset, 0), xycoords=('axes fraction', 'data'), box_alignment=(1, .5), boxcoords='offset points', bboxprops={ 'edgecolor': 'none', 'facecolor': 'none' }, arrowprops={ 'arrowstyle': '-', 'shrinkA': 0, 'shrinkB': 1 }, pad=0.1) ax.add_artist(ab) zorder = ab.zorder else: zorder = 0 if self.marker: if self.final_image is not None: markersize = max(self.final_image.size) else: markersize = 50 markersize = markersize * size d = DrawingArea(markersize, markersize) if self.marker_front: zorder_marker = zorder + 0.1 else: zorder_marker = zorder - 0.1 d.set_zorder(zorder_marker) d.set_alpha(0) if self.marker_front: d.add_artist( plt.Line2D([markersize / 2], [markersize / 2], marker=self.marker, markeredgecolor=self.col, markerfacecolor=(0, 0, 0, 0), markersize=markersize, markeredgewidth=self.markeredgewidth, transform=d.get_transform(), zorder=zorder_marker)) else: d.add_artist( plt.Line2D([markersize / 2], [markersize / 2], marker=self.marker, markeredgecolor=self.col, markerfacecolor=self.col, markersize=markersize, markeredgewidth=self.markeredgewidth, transform=d.get_transform(), zorder=zorder_marker)) ab_marker = AnnotationBbox(d, (0, y), xybox=(-offset, 0), xycoords=('axes fraction', 'data'), box_alignment=(1, 0.5), boxcoords='offset points', bboxprops={ 'edgecolor': 'none', 'facecolor': 'none' }, arrowprops={ 'arrowstyle': '-', 'shrinkA': 0, 'shrinkB': 1 }, pad=0.1) ab_marker.set_zorder(zorder_marker) ab_marker.set_alpha(0) ax.add_artist(ab_marker) if self.string is not None: ax.annotate(self.string, (0, y), xytext=(-offset, 0), xycoords=('axes fraction', 'data'), textcoords='offset points', horizontalalignment='right', verticalalignment='center', arrowprops={ 'arrowstyle': '-', 'shrinkA': 0, 'shrinkB': 1 }, zorder=zorder + 1, fontsize=self.fontsize, fontname=self.fontname, color=self.fontcolor)
def _tick_label( self, x, y, size, ax=None, linewidth=None, xybox=None, xycoords=None, box_alignment=None, horizontalalignment=None, verticalalignment=None, rotation=None, ): """ uses the icon as a ticklabel at location x Args: x (float) the horizontal position of the tick y (float) the vertical position of the tick size (float) scaling the size of the icon ax (matplotlib axis) the axis to put the label on """ ret_val = {} if ax is None: ax = plt.gca() tickline_color = self.color # np.any chokes on str input so need to test for this first if not (isinstance(tickline_color, str) or np.any(tickline_color)): tickline_color = [0.8, 0.8, 0.8] if self.final_image is not None: imagebox = OffsetImage(self.final_image, zoom=size, dpi_cor=True) ret_val['image'] = AnnotationBbox( imagebox, (x, y), xybox=xybox, xycoords=xycoords, box_alignment=box_alignment, boxcoords="offset points", bboxprops={ "edgecolor": "none", "facecolor": "none" }, arrowprops={ "linewidth": linewidth, "color": tickline_color, "arrowstyle": "-", "shrinkA": 0, "shrinkB": 1, }, pad=0.0, annotation_clip=False, ) zorder = ret_val['image'].zorder ax.add_artist(ret_val['image']) else: zorder = 0 if self.marker: if self.final_image is not None: markersize = max(self.final_image.size) else: markersize = 50 markersize = markersize * size d = DrawingArea(markersize, markersize) if self.marker_front: zorder_marker = zorder + 0.1 else: zorder_marker = zorder - 0.1 d.set_zorder(zorder_marker) d.set_alpha(0) if self.marker_front: d.add_artist( plt.Line2D( [markersize / 2], [markersize / 2], marker=self.marker, markeredgecolor=self.color, markerfacecolor=(0, 0, 0, 0), markersize=markersize, markeredgewidth=self.markeredgewidth, transform=d.get_transform(), zorder=zorder_marker, )) else: d.add_artist( plt.Line2D( [markersize / 2], [markersize / 2], marker=self.marker, markeredgecolor=self.color, markerfacecolor=self.color, markersize=markersize, markeredgewidth=self.markeredgewidth, transform=d.get_transform(), zorder=zorder_marker, )) ret_val['marker'] = AnnotationBbox( d, (x, y), xybox=xybox, xycoords=xycoords, box_alignment=box_alignment, boxcoords="offset points", bboxprops={ "edgecolor": "none", "facecolor": "none" }, arrowprops={ "linewidth": linewidth, "color": tickline_color, "arrowstyle": "-", "shrinkA": 0, "shrinkB": 1, }, pad=0.0, annotation_clip=False, ) ret_val['marker'].set_zorder(zorder_marker) ret_val['marker'].set_alpha(0) ax.add_artist(ret_val['marker']) if self.string is not None: ret_val['string'] = ax.annotate( self.string, (x, y), xytext=xybox, xycoords=xycoords, textcoords="offset points", horizontalalignment=horizontalalignment, verticalalignment=verticalalignment, arrowprops={ "linewidth": linewidth, "color": tickline_color, "arrowstyle": "-", "shrinkA": 0, "shrinkB": 1, }, zorder=zorder + 0.2, fontsize=self.font_size, fontname=self.font_name, color=self.font_color, rotation=rotation, ) return ret_val