def _offset(ax, x, y): """Provide offset in pixels Parameters ---------- x : int Offset in pixels for x y : int Offset in pixels for y Idea borrowed from http://www.scipy.org/Cookbook/Matplotlib/Transformations but then heavily extended to be compatible with many reincarnations of matplotlib """ d = dir(mlt) if 'offset_copy' in d: # tested with python-matplotlib 0.98.3-5 # ??? if pukes, might need to replace 2nd parameter from # ax to ax.get_figure() return mlt.offset_copy(ax.transData, ax, x=x, y=y, units='dots') elif 'BlendedAffine2D' in d: # some newer versions of matplotlib return ax.transData + \ mlt.Affine2D().translate(x,y) elif 'blend_xy_sep_transform' in d: trans = mlt.blend_xy_sep_transform(ax.transData, ax.transData) # Now we set the offset in pixels trans.set_offset((x, y), mlt.identity_transform()) return trans else: raise RuntimeError, \ "Lacking needed functions in matplotlib.transform " \ "for _offset. Please upgrade"
def _offset(ax, x, y): """Provide offset in pixels Parameters ---------- x : int Offset in pixels for x y : int Offset in pixels for y Idea borrowed from http://www.scipy.org/Cookbook/Matplotlib/Transformations but then heavily extended to be compatible with many reincarnations of matplotlib """ d = dir(mlt) if "offset_copy" in d: # tested with python-matplotlib 0.98.3-5 # ??? if pukes, might need to replace 2nd parameter from # ax to ax.get_figure() return mlt.offset_copy(ax.transData, ax, x=x, y=y, units="dots") elif "BlendedAffine2D" in d: # some newer versions of matplotlib return ax.transData + mlt.Affine2D().translate(x, y) elif "blend_xy_sep_transform" in d: trans = mlt.blend_xy_sep_transform(ax.transData, ax.transData) # Now we set the offset in pixels trans.set_offset((x, y), mlt.identity_transform()) return trans else: raise RuntimeError, "Lacking needed functions in matplotlib.transform " "for _offset. Please upgrade"
def drawLine(self, xData, yData, renderer): line = Line2D( xdata=xData, ydata=yData, color=rcParams['grid.color'], #linestyle=rcParams['grid.linestyle'], linewidth=rcParams['grid.linewidth'], antialiased=True, ) line.set_transform( blend_xy_sep_transform( self.axes.transData, self.axes.transData) ) line.set_clip_box(self.axes.bbox) #self._set_artist_props(line) line.draw(renderer)
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 offset(ax, x, y): # This trick makes a shallow copy of ax.transData (but fails for polar plots): trans = blend_xy_sep_transform(ax.transData, ax.transData) # Now we set the offset in pixels trans.set_offset((x, y), identity_transform()) return trans
def offset(ax, x, y): # This trick makes a shallow copy of ax.transData (but fails for polar plots): trans = blend_xy_sep_transform(ax.transData, ax.transData) # Now we set the offset in pixels trans.set_offset((x,y), identity_transform()) return trans
class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t x, y = rand(2, 10000) indStart, indEnd = 30, 350 for i in range(indEnd): for j in range(20): l = Line() t1 = rand_transform() t2 = rand_transform() trans = blend_xy_sep_transform(t1, t2) l.set_transform(trans) xt, yt = trans.numerix_x_y(x, y) xytup = tuple(rand(2)) txytup = trans.xy_tup(xytup) ixytup = trans.inverse_xy_tup(xytup) seqt = trans.seq_xy_tups(zip(x, y)) gc.collect() val = report_memory(i) if i == indStart: start = val # wait a few cycles for memory usage to stabilize end = val print 'Average memory consumed per loop: %1.4fk bytes\n' % ( (end - start) / float(indEnd - indStart))
class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t x, y = rand(2,10000) indStart, indEnd = 30, 350 for i in range(indEnd): for j in range(20): l = Line() t1 = rand_transform() t2 = rand_transform() trans = blend_xy_sep_transform( t1, t2) l.set_transform(trans) xt, yt = trans.numerix_x_y(x, y) xytup = tuple(rand(2)) txytup = trans.xy_tup(xytup) ixytup = trans.inverse_xy_tup(xytup) seqt = trans.seq_xy_tups(zip(x,y)) gc.collect() val = report_memory(i) if i==indStart: start = val # wait a few cycles for memory usage to stabilize end = val print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))
def rand_transform(): b1 = rand_bbox() b2 = rand_bbox() return get_bbox_transform(b1, b2) class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t indStart, indEnd = 30, 250 for i in range(indEnd): l = Line() t1 = rand_transform() t2 = rand_transform() l.set_transform(blend_xy_sep_transform(t1, t2)) val = report_memory(i) if i == indStart: start = val # wait a few cycles for memory usage to stabilize end = val print 'Average memory consumed per loop: %1.4fk bytes\n' % ( (end - start) / float(indEnd - indStart))
return Bbox(ll, ur) def rand_transform(): b1 = rand_bbox() b2 = rand_bbox() return get_bbox_transform(b1, b2) class Line: def __init__(self): self._transform = identity_transform() def set_transform(self, t): self._transform = t indStart, indEnd = 30, 250 for i in range(indEnd): l = Line() t1 = rand_transform() t2 = rand_transform() l.set_transform(blend_xy_sep_transform( t1, t2)) val = report_memory(i) if i==indStart: start = val # wait a few cycles for memory usage to stabilize end = val print 'Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart))