def offset_copy(trans, fig=None, x=0, y=0, units='inches'): ''' Return a shallow copy of a transform with an added offset. args: trans is any transform kwargs: fig is the current figure; it can be None if units are 'dots' x, y give the offset units is 'inches', 'points' or 'dots' ''' newtrans = trans.shallowcopy() if units == 'dots': newtrans.set_offset((x, y), identity_transform()) return newtrans if fig is None: raise ValueError('For units of inches or points a fig kwarg is needed') if units == 'points': x /= 72.0 y /= 72.0 elif not units == 'inches': raise ValueError('units must be dots, points, or inches') tx = Value(x) * fig.dpi ty = Value(y) * fig.dpi newtrans.set_offset((0, 0), translation_transform(tx, ty)) return newtrans
def bbox_all(bboxes): """ Return the Bbox that bounds all bboxes """ # this is a good candidate to move to _transforms assert (len(bboxes)) if len(bboxes) == 1: return bboxes[0] bbox = bboxes[0] minx = bbox.xmin() miny = bbox.ymin() maxx = bbox.xmax() maxy = bbox.ymax() for bbox in bboxes[1:]: thisminx = bbox.xmin() thisminy = bbox.ymin() thismaxx = bbox.xmax() thismaxy = bbox.ymax() if thisminx < minx: minx = thisminx if thismaxx > maxx: maxx = thismaxx if thisminy < miny: miny = thisminy if thismaxy > maxy: maxy = thismaxy return Bbox(Point(Value(minx), Value(miny)), Point(Value(maxx), Value(maxy)))
def inverse_transform_bbox(trans, bbox): 'inverse transform the bbox' xmin, xmax = bbox.intervalx().get_bounds() ymin, ymax = bbox.intervaly().get_bounds() xmin, ymin = trans.inverse_xy_tup((xmin, ymin)) xmax, ymax = trans.inverse_xy_tup((xmax, ymax)) return Bbox(Point(Value(xmin), Value(ymin)), Point(Value(xmax), Value(ymax)))
def bound_vertices(verts): """ Return the Bbox of the sequence of x,y tuples in verts """ # this is a good candidate to move to _transforms xs = [x for x, y in verts] ys = [y for x, y in verts] minx = min(xs) maxx = max(xs) miny = min(ys) maxy = max(ys) return Bbox(Point(Value(minx), Value(miny)), Point(Value(maxx), Value(maxy)))
def copy_bbox_transform(trans): 'return a deep copy of the bbox transform' inbox = trans.get_bbox1() xmin, xmax = inbox.intervalx().get_bounds() ymin, ymax = inbox.intervaly().get_bounds() newInbox = Bbox(Point(Value(xmin), Value(ymin)), Point(Value(xmax), Value(ymax))) outbox = trans.get_bbox2() xmin, xmax = outbox.intervalx().get_bounds() ymin, ymax = outbox.intervaly().get_bounds() newOutbox = Bbox(Point(Value(xmin), Value(ymin)), Point(Value(xmax), Value(ymax))) typex = trans.get_funcx().get_type() typey = trans.get_funcy().get_type() newtrans = get_bbox_transform(newInbox, newOutbox) newtrans.get_funcx().set_type(typex) newtrans.get_funcy().set_type(typey) return newtrans
#tz = _get_rc_timezone() d1 = datetime.datetime(2000, 3, 1, tzinfo=tz) d2 = datetime.datetime(2000, 3, 5, tzinfo=tz) #d1 = datetime.datetime( 2002, 1, 5, tzinfo=tz) #d2 = datetime.datetime( 2003, 12, 1, tzinfo=tz) delta = datetime.timedelta(hours=6) dates = drange(d1, d2, delta) # MGDTODO: Broken on transforms branch #print 'orig', d1 #print 'd2n and back', num2date(date2num(d1), tz) from _transforms import Value, Interval v1 = Value(date2num(d1)) v2 = Value(date2num(d2)) dlim = Interval(v1, v2) vlim = Interval(v1, v2) #locator = HourLocator(byhour=(3,15), tz=tz) #locator = MinuteLocator(byminute=(15,30,45), tz=tz) #locator = YearLocator(base=5, month=7, day=4, tz=tz) #locator = MonthLocator(bymonthday=15) locator = DayLocator(tz=tz) locator.set_data_interval(dlim) locator.set_view_interval(vlim) dmin, dmax = locator.autoscale() vlim.set_bounds(dmin, dmax) ticks = locator()
def lbwh_to_bbox(l, b, w, h): return Bbox(Point(Value(l), Value(b)), Point(Value(l + w), Value(b + h)))
def one(): return Value(1)
def zero(): return Value(0)
def one() : return Value(1) def origin():
def zero(): return Value(0) def one() : return Value(1)