Example #1
0
    def __init__(self, fig, rect=[0.0, 0.0, 1.0, 1.0], *args, **kwargs):
        self.fig = fig

        azim = cbook.popd(kwargs, 'azim', -60)
        elev = cbook.popd(kwargs, 'elev', 30)

        self.xy_viewLim = unit_bbox()
        self.zz_viewLim = unit_bbox()
        self.xy_dataLim = unit_bbox()
        self.zz_dataLim = unit_bbox()
        # inihibit autoscale_view until the axises are defined
        # they can't be defined until Axes.__init__ has been called
        self._ready = 0
        Axes.__init__(self, self.fig, rect,
                      frameon=True,
                      xticks=[], yticks=[], *args, **kwargs)

        self.M = None
        self._ready = 1

        self.view_init(elev, azim)
        self.mouse_init()
        self.create_axes()
        self.set_top_view()

        #self.axesPatch.set_edgecolor((1,0,0,0))
        self.axesPatch.set_linewidth(0)
        #self.axesPatch.set_facecolor((0,0,0,0))
        self.fig.add_axes(self)
Example #2
0
    def plot_wireframe(self, X, Y, Z, *args, **kwargs):
        rstride = cbook.popd(kwargs, "rstride", 1)
        cstride = cbook.popd(kwargs, "cstride", 1)

        had_data = self.has_data()
        rows,cols = Z.shape

        tX,tY,tZ = npy.transpose(X), npy.transpose(Y), npy.transpose(Z)

        rii = [i for i in range(0,rows,rstride)]+[rows-1]
        cii = [i for i in range(0,cols,cstride)]+[cols-1]
        xlines = [X[i] for i in rii]
        ylines = [Y[i] for i in rii]
        zlines = [Z[i] for i in rii]
        #
        txlines = [tX[i] for i in cii]
        tylines = [tY[i] for i in cii]
        tzlines = [tZ[i] for i in cii]
        #
        lines = [zip(xl,yl,zl) for xl,yl,zl in zip(xlines,ylines,zlines)]
        lines += [zip(xl,yl,zl) for xl,yl,zl in zip(txlines,tylines,tzlines)]
        linec = self.add_lines(lines, *args, **kwargs)

        self.auto_scale_xyz(X,Y,Z, had_data)
        return linec
Example #3
0
    def __init__(self, xy, radius=5, **kwargs):
        if kwargs.has_key("resolution"):
            import warnings

            warnings.warn("Circle is now scale free.  Use CirclePolygon instead!", DeprecationWarning)
            popd(kwargs, "resolution")

        self.radius = radius
        Ellipse.__init__(self, xy, radius * 2, radius * 2, **kwargs)
Example #4
0
    def __init__(self, xy, radius=5, **kwargs):
        if kwargs.has_key('resolution'):
            import warnings
            warnings.warn(
                'Circle is now scale free.  Use CirclePolygon instead!',
                DeprecationWarning)
            popd(kwargs, 'resolution')

        self.radius = radius
        Ellipse.__init__(self, xy, radius * 2, radius * 2, **kwargs)
Example #5
0
    def plot_surface(self, X, Y, Z, *args, **kwargs):
        had_data = self.has_data()

        rows, cols = Z.shape
        tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
        rstride = cbook.popd(kwargs, 'rstride', 10)
        cstride = cbook.popd(kwargs, 'cstride', 10)
        #
        polys = []
        boxes = []
        for rs in np.arange(0, rows - 1, rstride):
            for cs in np.arange(0, cols - 1, cstride):
                ps = []
                corners = []
                for a, ta in [(X, tX), (Y, tY), (Z, tZ)]:
                    ztop = a[rs][cs:min(cols, cs + cstride + 1)]
                    zleft = ta[min(cols - 1, cs +
                                   cstride)][rs:min(rows, rs + rstride + 1)]
                    zbase = a[min(rows - 1, rs +
                                  rstride)][cs:min(cols, cs + cstride + 1):]
                    zbase = zbase[::-1]
                    zright = ta[cs][rs:min(rows, rs + rstride + 1):]
                    zright = zright[::-1]
                    corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]])
                    z = np.concatenate((ztop, zleft, zbase, zright))
                    ps.append(z)
                boxes.append(map(np.array, zip(*corners)))
                polys.append(zip(*ps))
        #
        lines = []
        shade = []
        for box in boxes:
            n = proj3d.cross(box[0] - box[1], box[0] - box[2])
            n = n / proj3d.mod(n) * 5
            shade.append(np.dot(n, [-1, -1, 0.5]))
            lines.append((box[0], n + box[0]))
        #
        color = np.array([0, 0, 1, 1])
        norm = Normalize(min(shade), max(shade))
        colors = [color * (0.5 + norm(v) * 0.5) for v in shade]
        for c in colors:
            c[3] = 1
        polyc = art3d.Poly3DCollection(polys,
                                       facecolors=colors,
                                       *args,
                                       **kwargs)
        polyc._zsort = 1
        self.add_collection(polyc)
        #
        self.auto_scale_xyz(X, Y, Z, had_data)
        return polyc
Example #6
0
def bbox_artist(artist, renderer, props=None, fill=True):
    """
    This is a debug function to draw a rectangle around the bounding
    box returned by get_window_extent of an artist, to test whether
    the artist is returning the correct bbox

    props is a dict of rectangle props with the additional property
    'pad' that sets the padding around the bbox in points
    """
    if props is None: props = {}
    props = props.copy()  # don't want to alter the pad externally
    pad = popd(props, 'pad', 4)
    pad = renderer.points_to_pixels(pad)
    bbox = artist.get_window_extent(renderer)
    l, b, w, h = bbox.get_bounds()
    l -= pad / 2.
    b -= pad / 2.
    w += pad
    h += pad
    r = Rectangle(
        xy=(l, b),
        width=w,
        height=h,
        fill=fill,
    )
    r.set_clip_on(False)
    r.update(props)
    r.draw(renderer)
Example #7
0
def bbox_artist(artist, renderer, props=None, fill=True):
    """
    This is a debug function to draw a rectangle around the bounding
    box returned by get_window_extent of an artist, to test whether
    the artist is returning the correct bbox

    props is a dict of rectangle props with the additional property
    'pad' that sets the padding around the bbox in points
    """
    if props is None: props = {}
    props = props.copy() # don't want to alter the pad externally
    pad = popd(props, 'pad', 4)
    pad = renderer.points_to_pixels(pad)
    bbox = artist.get_window_extent(renderer)
    l,b,w,h = bbox.get_bounds()
    l-=pad/2.
    b-=pad/2.
    w+=pad
    h+=pad
    r = Rectangle(xy=(l,b),
                  width=w,
                  height=h,
                  fill=fill,
                  )
    r.set_clip_on( False )
    r.update(props)
    r.draw(renderer)
Example #8
0
    def plot_surface(self, X, Y, Z, *args, **kwargs):
        had_data = self.has_data()

        rows, cols = Z.shape
        tX,tY,tZ = npy.transpose(X), npy.transpose(Y), npy.transpose(Z)
        rstride = cbook.popd(kwargs, 'rstride', 10)
        cstride = cbook.popd(kwargs, 'cstride', 10)
        #
        polys = []
        boxes = []
        for rs in npy.arange(0,rows-1,rstride):
            for cs in npy.arange(0,cols-1,cstride):
                ps = []
                corners = []
                for a,ta in [(X,tX),(Y,tY),(Z,tZ)]:
                    ztop = a[rs][cs:min(cols,cs+cstride+1)]
                    zleft = ta[min(cols-1,cs+cstride)][rs:min(rows,rs+rstride+1)]
                    zbase = a[min(rows-1,rs+rstride)][cs:min(cols,cs+cstride+1):]
                    zbase = zbase[::-1]
                    zright = ta[cs][rs:min(rows,rs+rstride+1):]
                    zright = zright[::-1]
                    corners.append([ztop[0],ztop[-1],zbase[0],zbase[-1]])
                    z = npy.concatenate((ztop,zleft,zbase,zright))
                    ps.append(z)
                boxes.append(map(npy.array,zip(*corners)))
                polys.append(zip(*ps))
        #
        lines = []
        shade = []
        for box in boxes:
            n = proj3d.cross(box[0]-box[1],
                         box[0]-box[2])
            n = n/proj3d.mod(n)*5
            shade.append(npy.dot(n,[-1,-1,0.5]))
            lines.append((box[0],n+box[0]))
        #
        color = npy.array([0,0,1,1])
        norm = Normalize(min(shade),max(shade))
        colors = [color * (0.5+norm(v)*0.5) for v in shade]
        for c in colors: c[3] = 1
        polyc = art3d.Poly3DCollection(polys, facecolors=colors, *args, **kwargs)
        polyc._zsort = 1
        self.add_collection(polyc)
        #
        self.auto_scale_xyz(X,Y,Z, had_data)
        return polyc
Example #9
0
    def plot(self, *args, **kwargs):
        had_data = self.has_data()

        zval = cbook.popd(kwargs, 'z', 0)
        zdir = cbook.popd(kwargs, 'dir', 'z')
        lines = Axes.plot(self, *args, **kwargs)
        #
        linecs = [art3d.Line2DW(l, z=zval, dir=zdir) for l in lines]
        #
        xs = lines[0].get_xdata()
        ys = lines[0].get_ydata()
        zs = [zval for x in xs]
        xs,ys,zs = art3d.juggle_axes(xs,ys,zs,zdir)
        #
        self.auto_scale_xyz(xs,ys,zs, had_data)
        #
        return linecs
Example #10
0
    def add_axes(self, *args, **kwargs):
        """
Add an a axes with axes rect [left, bottom, width, height] where all
quantities are in fractions of figure width and height.  kwargs are
legal Axes kwargs plus"polar" which sets whether to create a polar axes

    add_axes((l,b,w,h))
    add_axes((l,b,w,h), frameon=False, axisbg='g')
    add_axes((l,b,w,h), polar=True)
    add_axes(ax)   # add an Axes instance


If the figure already has an axes with key *args, *kwargs then it will
simply make that axes current and return it.  If you do not want this
behavior, eg you want to force the creation of a new axes, you must
use a unique set of args and kwargs.  The artist "label" attribute has
been exposed for this purpose.  Eg, if you want two axes that are
otherwise identical to be added to the axes, make sure you give them
unique labels:

    add_axes((l,b,w,h), label='1')
    add_axes((l,b,w,h), label='2')

The Axes instance will be returned
        """

        if iterable(args[0]):
            key = tuple(args[0]), tuple(kwargs.items())
        else:
            key = args[0], tuple(kwargs.items())            

        if self._seen.has_key(key):
            ax = self._seen[key]
            self.sca(ax)
            return ax

        if not len(args): return        
        if isinstance(args[0], Axes):
            a = args[0]
            a.set_figure(self)
        else:
            rect = args[0]
            ispolar = popd(kwargs, 'polar', False)

            if ispolar:
                a = PolarAxes(self, rect, **kwargs)
            else:
                a = Axes(self, rect, **kwargs)            
                

        self.axes.append(a)
        self._axstack.push(a)
        self.sca(a)
        self._seen[key] = a
        return a
Example #11
0
    def add_axes(self, *args, **kwargs):
        """
Add an a axes with axes rect [left, bottom, width, height] where all
quantities are in fractions of figure width and height.  kwargs are
legal Axes kwargs plus"polar" which sets whether to create a polar axes

    add_axes((l,b,w,h))
    add_axes((l,b,w,h), frameon=False, axisbg='g')
    add_axes((l,b,w,h), polar=True)
    add_axes(ax)   # add an Axes instance


If the figure already has an axes with key *args, *kwargs then it will
simply make that axes current and return it.  If you do not want this
behavior, eg you want to force the creation of a new axes, you must
use a unique set of args and kwargs.  The artist "label" attribute has
been exposed for this purpose.  Eg, if you want two axes that are
otherwise identical to be added to the axes, make sure you give them
unique labels:

    add_axes((l,b,w,h), label='1')
    add_axes((l,b,w,h), label='2')

The Axes instance will be returned
        """

        if iterable(args[0]):
            key = tuple(args[0]), tuple(kwargs.items())
        else:
            key = args[0], tuple(kwargs.items())

        if self._seen.has_key(key):
            ax = self._seen[key]
            self.sca(ax)
            return ax

        if not len(args): return
        if isinstance(args[0], Axes):
            a = args[0]
            a.set_figure(self)
        else:
            rect = args[0]
            ispolar = popd(kwargs, 'polar', False)

            if ispolar:
                a = PolarAxes(self, rect, **kwargs)
            else:
                a = Axes(self, rect, **kwargs)

        self.axes.append(a)
        self._axstack.push(a)
        self.sca(a)
        self._seen[key] = a
        return a
Example #12
0
    def add_axes(self, *args, **kwargs):
        """
Add an a axes with axes rect [left, bottom, width, height] where all
quantities are in fractions of figure width and height.  kwargs are
legal Axes kwargs plus"polar" which sets whether to create a polar axes

    add_axes((l,b,w,h))
    add_axes((l,b,w,h), frameon=False, axisbg='g')
    add_axes((l,b,w,h), polar=True)
    add_axes(ax)   # add an Axes instance


If the figure already has an axed with key *args, *kwargs then it
will simply make that axes current and return it

The Axes instance will be returned
        """

        if iterable(args[0]):
            key = tuple(args[0]), tuple(kwargs.items())
        else:
            key = args[0], tuple(kwargs.items())            

        if self._seen.has_key(key):
            ax = self._seen[key]
            self.sca(ax)
            return ax

        if not len(args): return        
        if isinstance(args[0], Axes):
            a = args[0]
            a.set_figure(self)
        else:
            rect = args[0]
            ispolar = popd(kwargs, 'polar', False)

            if ispolar:
                a = PolarAxes(self, rect, **kwargs)
            else:
                a = Axes(self, rect, **kwargs)            
                

        self.axes.append(a)
        self._axstack.push(a)
        self.sca(a)
        self._seen[key] = a
        return a
Example #13
0
    def add_axes(self, *args, **kwargs):
        """
Add an a axes with axes rect [left, bottom, width, height] where all
quantities are in fractions of figure width and height.  kwargs are
legal Axes kwargs plus"polar" which sets whether to create a polar axes

    add_axes((l,b,w,h))
    add_axes((l,b,w,h), frameon=False, axisbg='g')
    add_axes((l,b,w,h), polar=True)
    add_axes(ax)   # add an Axes instance


If the figure already has an axed with key *args, *kwargs then it
will simply make that axes current and return it

The Axes instance will be returned
        """

        if iterable(args[0]):
            key = tuple(args[0]), tuple(kwargs.items())
        else:
            key = args[0], tuple(kwargs.items())

        if self._seen.has_key(key):
            ax = self._seen[key]
            self.sca(ax)
            return ax

        if not len(args): return
        if isinstance(args[0], Axes):
            a = args[0]
            a.set_figure(self)
        else:
            rect = args[0]
            ispolar = popd(kwargs, 'polar', False)

            if ispolar:
                a = PolarAxes(self, rect, **kwargs)
            else:
                a = Axes(self, rect, **kwargs)

        self.axes.append(a)
        self._axstack.push(a)
        self.sca(a)
        self._seen[key] = a
        return a
Example #14
0
    def add_subplot(self, *args, **kwargs):
        """
        Add a subplot.  Examples

            add_subplot(111)
            add_subplot(212, axisbg='r')  # add subplot with red background
            add_subplot(111, polar=True)  # add a polar subplot
            add_subplot(sub)              # add Subplot instance sub

        kwargs are legal Axes kwargs plus"polar" which sets whether to create a
        polar axes.  The Axes instance will be returned.

        If the figure already has a subplot with key *args, *kwargs then it will
        simply make that subplot current and return it
        """

        key = self._make_key(*args, **kwargs)

        if self._seen.has_key(key):
            ax = self._seen[key]
            self.sca(ax)
            return ax


        if not len(args): return

        if isinstance(args[0], Subplot) or isinstance(args, PolarSubplot):
            a = args[0]
            a.set_figure(self)
        else:
            ispolar = popd(kwargs, 'polar', False)
            if ispolar:
                a = PolarSubplot(self, *args, **kwargs)
            else:
                a = Subplot(self, *args, **kwargs)


        self.axes.append(a)
        self._axstack.push(a)
        self.sca(a)
        self._seen[key] = a
        return a