Exemple #1
0
    def __init__(
            self,
            figsize=None,  # defaults to rc figure.figsize
            dpi=None,  # defaults to rc figure.dpi
            facecolor=None,  # defaults to rc figure.facecolor
            edgecolor=None,  # defaults to rc figure.edgecolor
            linewidth=1.0,  # the default linewidth of the frame
            frameon=True,  # whether or not to draw the figure frame
            subplotpars=None,  # default to rc
    ):
        """
        figsize is a w,h tuple in inches
        dpi is dots per inch
        subplotpars is a SubplotParams instance, defaults to rc
        """
        Artist.__init__(self)
        #self.set_figure(self)
        self._axstack = Stack()  # maintain the current axes
        self._axobservers = []
        self._seen = {}  # axes args we've seen

        if figsize is None: figsize = rcParams['figure.figsize']
        if dpi is None: dpi = rcParams['figure.dpi']
        if facecolor is None: facecolor = rcParams['figure.facecolor']
        if edgecolor is None: edgecolor = rcParams['figure.edgecolor']

        self._unit_conversions = {}

        self.dpi = Value(dpi)
        self.figwidth = Value(figsize[0])
        self.figheight = Value(figsize[1])
        self.ll = Point(Value(0), Value(0))
        self.ur = Point(self.figwidth * self.dpi, self.figheight * self.dpi)
        self.bbox = Bbox(self.ll, self.ur)

        self.frameon = frameon

        self.transFigure = get_bbox_transform(unit_bbox(), self.bbox)

        self.figurePatch = Rectangle(
            xy=(0, 0),
            width=1,
            height=1,
            facecolor=facecolor,
            edgecolor=edgecolor,
            linewidth=linewidth,
        )
        self._set_artist_props(self.figurePatch)

        self._hold = rcParams['axes.hold']
        self.canvas = None

        if subplotpars is None:
            subplotpars = SubplotParams()

        self.subplotpars = subplotpars

        self.clf()

        self._cachedRenderer = None
Exemple #2
0
def parallel_pts_w_offset(cb, ce, dw):
    ''' compute positions of points that are in line parallel to cb->ce, dw away'''
    l_recip = 1.0 / (((cb.x - ce.x)**2 + (cb.y - ce.y)**2)**0.5)  # divide once
    pbx = cb.x + (dw * (ce.y - cb.y) * l_recip)
    pex = ce.x + (dw * (ce.y - cb.y) * l_recip)

    pby = cb.y + (dw * (cb.x - ce.x) * l_recip)
    pey = ce.y + (dw * (cb.x - ce.x) * l_recip)
    return (Point(pbx, pby, 0), Point(pex, pey, 0))
Exemple #3
0
def trans_valid_area_to_rect(bounds, trans, **kwargs):
    ''' elaborated version that provides a rect in the transformed position '''
    bl = Point(*bounds[0])
    tr = Point(*bounds[1])
    # apply transformation to the bounds
    poly = [bl, Point(bl.x, tr.y), tr, Point(tr.x, bl.y)]
    seq = [
        poly,
    ]
    # transform the polygon
    seq_tr = translate_group(rotate_group_about_ctr(seq, trans.theta),
                             trans.dx, trans.dy)
    return poly_from_seq(seq_tr[0], **kwargs)
Exemple #4
0
    def __init__(
        self,
        figsize=None,  # defaults to rc figure.figsize
        dpi=None,  # defaults to rc figure.dpi
        facecolor=None,  # defaults to rc figure.facecolor
        edgecolor=None,  # defaults to rc figure.edgecolor
        linewidth=1.0,  # the default linewidth of the frame
        frameon=True,
    ):
        """
        paper size is a w,h tuple in inches
        DPI is dots per inch 
        """
        Artist.__init__(self)
        #self.set_figure(self)
        self._axstack = Stack()  # maintain the current axes
        self._axobservers = []
        self._seen = {}  # axes args we've seen

        if figsize is None: figsize = rcParams['figure.figsize']
        if dpi is None: dpi = rcParams['figure.dpi']
        if facecolor is None: facecolor = rcParams['figure.facecolor']
        if edgecolor is None: edgecolor = rcParams['figure.edgecolor']

        self.dpi = Value(dpi)
        self.figwidth = Value(figsize[0])
        self.figheight = Value(figsize[1])
        self.ll = Point(Value(0), Value(0))
        self.ur = Point(self.figwidth * self.dpi, self.figheight * self.dpi)
        self.bbox = Bbox(self.ll, self.ur)
        self.frameon = frameon

        self.transFigure = get_bbox_transform(unit_bbox(), self.bbox)

        self.figurePatch = Rectangle(
            xy=(0, 0),
            width=1,
            height=1,
            facecolor=facecolor,
            edgecolor=edgecolor,
            linewidth=linewidth,
        )
        self._set_artist_props(self.figurePatch)

        self._hold = rcParams['axes.hold']
        self.clf()
Exemple #5
0
def gen_valid_bee_positions(valid_area,
                            n=1,
                            theta_rng=(0, 2 * pi),
                            trans=None):
    '''
    return a list of (x, y, theta) tuples, for locations of bees that
    are within the valid_area. '''
    # the area as given is untransformed - generate within this rectangle, uniformly
    # then transform all the points, and return them.
    xlims = valid_area[0][0], valid_area[1][0]
    ylims = valid_area[0][1], valid_area[1][1]

    # compute centre of the valid area
    bl = Point(*valid_area[0])
    tr = Point(*valid_area[1])
    poly = [bl, Point(bl.x, tr.y), tr, Point(tr.x, bl.y)]
    ctr = find_ctr_seq(poly)

    pts = []
    for i in xrange(n):
        x = random.uniform(*xlims)
        y = random.uniform(*ylims)
        yaw = random.uniform(*theta_rng)
        p = Point(x, y, 0)

        pts.append((p, yaw))

    # now we have the points in canonical positions, transform them appropriately
    pts_transformed = list(pts)
    if trans is None:
        pass
    else:
        pts_transformed = []
        for (p, yaw) in pts:
            p_tr = rotate_point_about_other(p, ctr, theta=trans.theta)
            p_tr = translate_point(p_tr, trans.dx, trans.dy)
            yaw_tr = yaw + trans.theta

            pts_transformed.append((p_tr, yaw_tr))

    return pts_transformed
Exemple #6
0
def pos_on_perim(cx, cy, theta, radius):
    x = cx + radius * cos(theta)
    y = cy + radius * sin(theta)
    return Point(x, y, 0)