def _get_text1(self, loc): 'Get the default Text instance' # the y loc is 3 points below the min of y axis # get the affine as an a,b,c,d,tx,ty list # x in data coords, y in axes coords #t = Text( t = TextWithDash( x=loc, y=0, fontproperties=FontProperties(size=rcParams['tick.labelsize']), color=rcParams['tick.color'], verticalalignment='top', horizontalalignment='center', dashdirection=0, xaxis=True, ) trans = blend_xy_sep_transform( self.axes.transData, self.axes.transAxes) #offset the text downward with a post transformation transOffset = translation_transform( Value(0), Value(-1)*self._padPixels) trans.set_offset( (0,0), transOffset) t.set_transform( trans) self._set_artist_props(t) return t
def _get_tick2line(self, loc): "Get the default line2D instance" # x in axes coords, y in data coords l = Line2D((1, 1), (0, 0), color="k", antialiased=False, marker=TICKLEFT, markersize=self._size) l.set_transform(blend_xy_sep_transform(self.axes.transAxes, self.axes.transData)) self._set_artist_props(l) return l
def _get_tick1line(self, loc): 'Get the default line2D instance' # x in axes coords, y in data coords l = Line2D( (0, 0), (loc, loc), color='k', antialiased=False, marker = TICKRIGHT, markersize=self._size, ) l.set_transform( blend_xy_sep_transform( self.axes.transAxes, self.axes.transData) ) self._set_artist_props(l) return l
def _get_offset_text(self): # x in axes coords, y in display coords (to be updated at draw time) offsetText = Text(x=1, y=0, fontproperties = FontProperties(size=rcParams['tick.labelsize']), color = rcParams['tick.color'], verticalalignment='top', horizontalalignment='right', ) offsetText.set_transform( blend_xy_sep_transform( self.axes.transAxes, identity_transform() )) self._set_artist_props(offsetText) self.offset_text_position='bottom' return offsetText
def _get_label(self): # x in axes coords, y in display coords (to be updated at draw # time by _update_label_positions label = Text(x=0.5, y=0, fontproperties = FontProperties(size=rcParams['axes.labelsize']), color = rcParams['axes.labelcolor'], verticalalignment='top', horizontalalignment='center', ) label.set_transform( blend_xy_sep_transform( self.axes.transAxes, identity_transform() )) self._set_artist_props(label) return label
def _get_tick2line(self, loc): 'Get the default line2D instance' # x in axes coords, y in data coords l = Line2D( (1,), (0,), color='k', antialiased=False, marker = self._ytickmarkers[1], linestyle = 'None', markersize=self._size, ) l.set_transform( blend_xy_sep_transform( self.axes.transAxes, self.axes.transData) ) self._set_artist_props(l) return l
def _get_gridline(self, loc): 'Get the default line2D instance' # x in data coords, y in axes coords l = Line2D( xdata=(loc, loc), ydata=(0, 1), color=rcParams['grid.color'], linestyle=rcParams['grid.linestyle'], linewidth=rcParams['grid.linewidth'], antialiased=False, ) l.set_transform( blend_xy_sep_transform( self.axes.transData, self.axes.transAxes) ) l.set_clip_box(self.axes.bbox) self._set_artist_props(l) return l
def _get_tick2line(self, loc): 'Get the default line2D instance' # x in data coords, y in axes coords l = Line2D( xdata=(loc, loc), ydata=(1,1), color='k', linestyle = 'None', antialiased=False, marker = TICKDOWN, markersize=self._size, ) l.set_transform( blend_xy_sep_transform( self.axes.transData, self.axes.transAxes) ) self._set_artist_props(l) return l
def __init__(self, ax, onselect, minspan=None, useblit=False, rectprops=None): """ Create a span selector in ax. When a selection is made, clear the span and call onselect with onselect(xmin, xmax) and clear the span. If minspan is not None, ignore events smaller than minspan The span rect is drawn with rectprops; default rectprops = dict(facecolor='red', alpha=0.5) set the visible attribute to False if you want to turn off the functionality of the span selector """ if rectprops is None: rectprops = dict(facecolor='red', alpha=0.5) self.ax = ax self.visible = True self.canvas = ax.figure.canvas self.canvas.mpl_connect('motion_notify_event', self.onmove) self.canvas.mpl_connect('button_press_event', self.press) self.canvas.mpl_connect('button_release_event', self.release) self.canvas.mpl_connect('draw_event', self.update_background) self.rect = None self.background = None self.rectprops = rectprops self.onselect = onselect self.useblit = useblit self.minspan = minspan trans = blend_xy_sep_transform(self.ax.transData, self.ax.transAxes) self.rect = Rectangle( (0,0), 0, 1, transform=trans, visible=False, **self.rectprops ) if not self.useblit: self.ax.add_patch(self.rect) self.pressx = None
def _get_label(self): # x in display coords (updated by _update_label_position) # y in axes coords label = Text(x=0, y=0.5, # todo: get the label position fontproperties=FontProperties(size=rcParams['axes.labelsize']), color = rcParams['axes.labelcolor'], verticalalignment='center', horizontalalignment='right', rotation='vertical', ) label.set_transform( blend_xy_sep_transform( identity_transform(), self.axes.transAxes) ) self._set_artist_props(label) return label
def _get_gridline(self, loc): 'Get the default line2D instance' # x in axes coords, y in data coords l = Line2D( xdata=(0, 1), ydata=(loc, loc), color=rcParams['grid.color'], linestyle=rcParams['grid.linestyle'], linewidth=rcParams['grid.linewidth'], antialiased=False, ) l.set_transform( blend_xy_sep_transform(self.axes.transAxes, self.axes.transData)) l.set_clip_box(self.axes.bbox) self._set_artist_props(l) return l
def _get_label(self): # x in display coords (updated by _update_label_position) # y in axes coords label = Text( x=0, y=0.5, # todo: get the label position fontproperties=FontProperties(size=rcParams['axes.labelsize']), color=rcParams['axes.labelcolor'], verticalalignment='center', horizontalalignment='right', rotation='vertical', ) label.set_transform( blend_xy_sep_transform(identity_transform(), self.axes.transAxes)) self._set_artist_props(label) return label
def _get_text2(self, loc): 'Get the default Text instance' # x in axes coords, y in data coords t = Text(x=1, y=loc, fontproperties=FontProperties(size=rcParams['tick.labelsize']), color=rcParams['tick.color'], verticalalignment='center', horizontalalignment='left', ) trans = blend_xy_sep_transform( self.axes.transAxes, self.axes.transData) # offset the text rightward with a post transformation transOffset = translation_transform( self._padPixels, Value(0)) trans.set_offset( (0,0), transOffset) t.set_transform( trans ) self._set_artist_props(t) return t
def _get_text1(self, loc): "Get the default Text instance" # x in axes coords, y in data coords t = Text( x=0, y=loc, fontproperties=FontProperties(size=rcParams["tick.labelsize"]), color=rcParams["tick.color"], verticalalignment="center", horizontalalignment="right", ) trans = blend_xy_sep_transform(self.axes.transAxes, self.axes.transData) # offset the text leftward with a post transformation transOffset = translation_transform(Value(-1) * self._padPixels, Value(0)) trans.set_offset((0, 0), transOffset) t.set_transform(trans) # t.set_transform( self.axes.transData ) self._set_artist_props(t) return t
def _get_text2(self, loc): 'Get the default Text 2 instance' # x in data coords, y in axes coords #t = Text( t = TextWithDash( x=loc, y=1, fontproperties=FontProperties(size=rcParams['tick.labelsize']), color=rcParams['tick.color'], verticalalignment='bottom', dashdirection=1, xaxis=True, horizontalalignment='center', ) trans = blend_xy_sep_transform( self.axes.transData, self.axes.transAxes) # offset the text upward with a post transformation transOffset = translation_transform( Value(0), self._padPixels) trans.set_offset( (0,0), transOffset) t.set_transform( trans ) self._set_artist_props(t) return t
def _get_text1(self, loc): 'Get the default Text instance' # the y loc is 3 points below the min of y axis # get the affine as an a,b,c,d,tx,ty list # x in data coords, y in axes coords t = Text( x=loc, y=0, fontproperties=FontProperties(size=rcParams['tick.labelsize']), color=rcParams['tick.color'], verticalalignment='top', horizontalalignment='center', ) trans = blend_xy_sep_transform(self.axes.transData, self.axes.transAxes) #offset the text downward with a post transformation transOffset = translation_transform(Value(0), Value(-1) * self._padPixels) trans.set_offset((0, 0), transOffset) t.set_transform(trans) self._set_artist_props(t) return t
def _get_text1(self, loc): 'Get the default Text instance' # x in axes coords, y in data coords #t = Text( t = TextWithDash( x=0, y=loc, fontproperties=FontProperties(size=rcParams['ytick.labelsize']), color=rcParams['ytick.color'], verticalalignment='center', horizontalalignment='right', dashdirection=0, xaxis=False, ) trans = blend_xy_sep_transform( self.axes.transAxes, self.axes.transData) # offset the text leftward with a post transformation transOffset = translation_transform( Value(-1)*self._padPixels, Value(0)) trans.set_offset( (0,0), transOffset) t.set_transform( trans ) #t.set_transform( self.axes.transData ) self._set_artist_props(t) return t
def _get_text2(self, loc): 'Get the default Text 2 instance' # x in data coords, y in axes coords #t = Text( t = TextWithDash( x=loc, y=1, fontproperties=FontProperties(size=rcParams['tick.labelsize']), color=rcParams['tick.color'], verticalalignment='bottom', dashdirection=1, xaxis=True, horizontalalignment='center', ) trans = blend_xy_sep_transform(self.axes.transData, self.axes.transAxes) # offset the text upward with a post transformation transOffset = translation_transform(Value(0), self._padPixels) trans.set_offset((0, 0), transOffset) t.set_transform(trans) self._set_artist_props(t) return t
def __init__(self, ax, onselect, direction, minspan=None, useblit=False, rectprops=None, onmove_callback=None): """ Create a span selector in ax. When a selection is made, clear the span and call onselect with onselect(vmin, vmax) and clear the span. direction must be 'horizontal' or 'vertical' If minspan is not None, ignore events smaller than minspan The span rect is drawn with rectprops; default rectprops = dict(facecolor='red', alpha=0.5) set the visible attribute to False if you want to turn off the functionality of the span selector """ if rectprops is None: rectprops = dict(facecolor='red', alpha=0.5) assert direction in ['horizontal', 'vertical'], 'Must choose horizontal or vertical for direction' self.direction = direction self.ax = ax self.visible = True self.canvas = ax.figure.canvas self.canvas.mpl_connect('motion_notify_event', self.onmove) self.canvas.mpl_connect('button_press_event', self.press) self.canvas.mpl_connect('button_release_event', self.release) self.canvas.mpl_connect('draw_event', self.update_background) self.rect = None self.background = None self.rectprops = rectprops self.onselect = onselect self.onmove_callback = onmove_callback self.useblit = useblit self.minspan = minspan # Needed when dragging out of axes self.buttonDown = False self.prev = (0, 0) if self.direction == 'horizontal': trans = blend_xy_sep_transform(self.ax.transData, self.ax.transAxes) w,h = 0,1 else: trans = blend_xy_sep_transform(self.ax.transAxes, self.ax.transData) w,h = 1,0 self.rect = Rectangle( (0,0), w, h, transform=trans, visible=False, **self.rectprops ) if not self.useblit: self.ax.add_patch(self.rect) self.pressv = None
def __init__(self, ax, onselect, direction, minspan=None, useblit=False, rectprops=None): """ Create a span selector in ax. When a selection is made, clear the span and call onselect with onselect(vmin, vmax) and clear the span. direction must be 'horizontal' or 'vertical' If minspan is not None, ignore events smaller than minspan The span rect is drawn with rectprops; default rectprops = dict(facecolor='red', alpha=0.5) set the visible attribute to False if you want to turn off the functionality of the span selector """ if rectprops is None: rectprops = dict(facecolor='red', alpha=0.5) assert direction in [ 'horizontal', 'vertical' ], 'Must choose horizontal or vertical for direction' self.direction = direction self.ax = ax self.visible = True self.canvas = ax.figure.canvas self.canvas.mpl_connect('motion_notify_event', self.onmove) self.canvas.mpl_connect('button_press_event', self.press) self.canvas.mpl_connect('button_release_event', self.release) self.canvas.mpl_connect('draw_event', self.update_background) self.rect = None self.background = None self.rectprops = rectprops self.onselect = onselect self.useblit = useblit self.minspan = minspan # Needed when dragging out of axes self.buttonDown = False self.prev = (0, 0) if self.direction == 'horizontal': trans = blend_xy_sep_transform(self.ax.transData, self.ax.transAxes) w, h = 0, 1 else: trans = blend_xy_sep_transform(self.ax.transAxes, self.ax.transData) w, h = 1, 0 self.rect = Rectangle((0, 0), w, h, transform=trans, visible=False, **self.rectprops) if not self.useblit: self.ax.add_patch(self.rect) self.pressv = None