Esempio n. 1
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

            rect = l,b,w,h
            add_axes(rect)
            add_axes(rect, frameon=False, axisbg='g')
            add_axes(rect, 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 figure, make sure you give them
        unique labels:

            add_axes(rect, label='axes1')
            add_axes(rect, label='axes2')

        The Axes instance will be returned

        The following kwargs are supported:
        %(Axes)s
        """

        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], Axes):
            a = args[0]
            assert (a.get_figure() is self)
        else:
            rect = args[0]
            ispolar = kwargs.pop('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
Esempio n. 2
0
    def add_axes(self, rect, axisbg=None, frameon=True, **kwargs):
        """
        Add an a axes with axes rect [left, bottom, width, height]
        where all quantities are in fractions of figure width and
        height.

        The Axes instance will be returned
        """
        if axisbg is None: axisbg = rcParams['axes.facecolor']
        ispolar = kwargs.get('polar', False)
        if ispolar:
            a = PolarAxes(self, rect, axisbg, frameon)
        else:
            a = Axes(self, rect, axisbg, frameon)
        self.axes.append(a)
        return a
Esempio n. 3
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
Esempio n. 4
0
    def new_axes(self, *args, **kwargs):
        '''
        Add an axes to the figure.
    
        :param position: (*list*) Optional, axes position specified by *position=* [left, bottom, width
            height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815].
        :param outerposition: (*list*) Optional, axes size and location, including labels and margin.
        :param aspect: (*string*) ['equal' | 'auto'] or a number. If a number the ratio of x-unit/y-unit in screen-space.
            Default is 'auto'.
        :param bgcolor: (*Color*) Optional, axes background color.
        :param axis: (*boolean*) Optional, set all axis visible or not. Default is ``True`` .
        :param bottomaxis: (*boolean*) Optional, set bottom axis visible or not. Default is ``True`` .
        :param leftaxis: (*boolean*) Optional, set left axis visible or not. Default is ``True`` .
        :param topaxis: (*boolean*) Optional, set top axis visible or not. Default is ``True`` .
        :param rightaxis: (*boolean*) Optional, set right axis visible or not. Default is ``True`` .
        :param xaxistype: (*string*) Optional, set x axis type as 'normal', 'lon', 'lat' or 'time'.
        :param xreverse: (*boolean*) Optional, set x axis reverse or not. Default is ``False`` .
        :param yreverse: (*boolean*) Optional, set yaxis reverse or not. Default is ``False`` .
        
        :returns: The axes.
        '''
        axestype = kwargs.pop('axestype', 'cartesian')
        polar = kwargs.pop('polar', False)
        if polar:
            axestype = 'polar'
         
        kwargs['figure'] = self
         
        if axestype == 'polar':
            ax = PolarAxes(*args, **kwargs)
            #self.__set_axes(ax, **kwargs)
        elif axestype == 'map':
            ax = MapAxes(*args, **kwargs)
            #self.__set_axesm(ax, **kwargs)
        elif axestype == '3d':
            ax = Axes3D(*args, **kwargs)
            #self.__set_axes3d(ax, **kwargs)
        else:
            ax = Axes(*args, **kwargs)
            #self.__set_axes(ax, **kwargs)
        #self.__set_axes_common(ax, *args, **kwargs)   

        return ax
Esempio n. 5
0
    def subplots(self, nrows=1, ncols=1, position=None, sharex=False, sharey=False, \
        wspace=None, hspace=None, axestype='Axes', **kwargs):
        '''
        Create a figure and a set of subplots.

        :param nrows: (*int*) Number of rows.
        :param ncols: (*int*) Number of cols.
        :param position: (*list*) All axes' position specified by *position=* [left, bottom, width
            height] in normalized (0, 1) units. Default is [0,0,1,1].
        :param sharex: (*boolean*) If share x axis.
        :param sharey: (*boolean*) If share y axis.
        :param subplot_kw: (*dict*) Subplot key words.
        :param wspace: (*float*) The amount of width reserved for blank space between subplots,
            expressed as a fraction of the average axis width.
        :param hspace: (*float*) The amount of height reserved for blank space between subplots,
            expressed as a fraction of the average axis height.
        :param axestype: (*string*) Axes type [Axes | Axes3D | MapAxes | PolarAxes].

        :returns: The figure and the axes tuple.
        '''
        if position is None:
            if wspace is None and hspace is None:
                position = [0, 0, 1, 1]
            else:
                position = [0.13, 0.11, 0.775, 0.815]
        left = float(position[0])
        bottom = float(position[1])
        width = float(position[2])
        height = float(position[3])

        chart = self.getChart()
        chart.setRowNum(nrows)
        chart.setColumnNum(ncols)
        axs = []
        ax2d = nrows > 1 and ncols > 1
        w = width / ncols
        h = height / nrows
        iswspace = False
        ishspace = False
        if not wspace is None and ncols > 1:
            w = (width - wspace * (ncols - 1)) / ncols
            iswspace = True
        if not hspace is None and nrows > 1:
            h = (height - hspace * (nrows - 1)) / nrows
            ishspace = True
        axestype = axestype.lower()
        y = bottom + height - h
        for i in range(nrows):
            if ax2d:
                axs2d = []
            x = left
            if ishspace:
                if i > 0:
                    y -= hspace
            for j in range(ncols):
                if axestype == 'axes3d':
                    ax = Axes3D()
                    self.__set_axes3d(ax, **kwarg)
                elif axestype == 'mapaxes':
                    ax = MapAxes()
                    self.__set_axesm(ax, **kwargs)
                elif axestype == 'polaraxes':
                    ax = PolarAxes()
                else:
                    ax = Axes()
                    self.__set_axes(ax, **kwargs)
                ax.axes.isSubPlot = True
                if not iswspace and not ishspace:
                    x = left + w * j
                    y = (bottom + height) - h * (i + 1)
                    ax.set_position([x, y, w, h])
                    ax.set_outerposition([x, y, w, h])
                    ax.active_outerposition(True)
                else:
                    if iswspace:
                        if j > 0:
                            x += wspace
                    ax.set_position([x, y, w, h])
                    ax.active_outerposition(False)
                    x += w
                if sharex:
                    if i < nrows - 1:
                        ax.axes.getAxis(
                            Location.BOTTOM).setDrawTickLabel(False)
                if sharey:
                    if j > 0:
                        ax.axes.getAxis(Location.LEFT).setDrawTickLabel(False)
                chart.addPlot(ax.axes)
                if ax2d:
                    axs2d.append(ax)
                else:
                    axs.append(ax)
            if ax2d:
                axs.append(tuple(axs2d))
            y -= h

        chart.setCurrentPlot(0)
        return tuple(axs)
Esempio n. 6
0
    def subplot(self, nrows, ncols, plot_number, **kwargs):
        """
        Returen a subplot axes positioned by the given grid definition.

        :param nrows, nrows: (*int*) Whree *nrows* and *ncols* are used to notionally spli the 
            figure into ``nrows * ncols`` sub-axes.
        :param plot_number: (*int) Is used to identify the particular subplot that this function
            is to create within the notional gird. It starts at 1, increments across rows first
            and has a maximum of ``nrows * ncols`` .

        :returns: Current axes specified by ``plot_number`` .
        """
        chart = self.getChart()
        chart.setRowNum(nrows)
        chart.setColumnNum(ncols)
        polar = kwargs.pop('polar', False)
        isnew = True
        if isnew:
            polar = kwargs.pop('polar', False)
            if polar:
                ax = PolarAxes()
            else:
                ax = Axes()
            ax.axes.isSubPlot = True
        else:
            chart.setCurrentPlot(plot_number - 1)
        position = kwargs.pop('position', None)
        if position is None:
            if isnew:
                if isinstance(plot_number, (list, tuple)):
                    i = 0
                    for pnum in plot_number:
                        pnum -= 1
                        rowidx = pnum / ncols
                        colidx = pnum % ncols
                        width = 1. / ncols
                        height = 1. / nrows
                        x = width * colidx
                        y = 1. - height * (rowidx + 1)
                        if i == 0:
                            minx = x
                            miny = y
                            maxx = x + width
                            maxy = y + height
                        else:
                            minx = min(x, minx)
                            miny = min(y, miny)
                            maxx = max(x + width, maxx)
                            maxy = max(y + height, maxy)
                        i += 1
                    x = minx
                    y = miny
                    width = maxx - minx
                    height = maxy - miny
                else:
                    plot_number -= 1
                    rowidx = plot_number / ncols
                    colidx = plot_number % ncols
                    width = 1. / ncols
                    height = 1. / nrows
                    x = width * colidx
                    y = 1. - height * (rowidx + 1)
                ax.set_position([x, y, width, height])
                ax.set_outerposition([x, y, width, height])
                ax.active_outerposition(True)
        else:
            ax.set_position(position)
            ax.active_outerposition(False)
        outerposition = kwargs.pop('outerposition', None)
        if not outerposition is None:
            ax.set_outerposition(outerposition)
            ax.active_outerposition(True)

        if isinstance(ax, MapAxes):
            self.__set_axesm(ax, **kwargs)
        else:
            self.__set_axes(ax, **kwargs)

        if isnew:
            chart.addPlot(ax.axes)
            chart.setCurrentPlot(chart.getPlots().size() - 1)

        return ax
Esempio n. 7
0
    def __create_axes(self, *args, **kwargs):
        """
        Create an axes.
        
        :param position: (*list*) Optional, axes position specified by *position=* [left, bottom, width
            height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815].
        :param outerposition: (*list*) Optional, axes size and location, including labels and margin.
        
        :returns: The axes.
        """
        if len(args) > 0:
            position = args[0]
        else:
            position = kwargs.pop('position', None)
        outerposition = kwargs.pop('outerposition', None)
        axestype = kwargs.pop('axestype', 'cartesian')
        polar = kwargs.pop('polar', False)
        if polar:
            axestype = 'polar'
        if axestype == 'polar':
            ax = PolarAxes()
        elif axestype == 'map':
            ax = MapAxes()
        elif axestype == '3d':
            ax = Axes3D()
        else:
            ax = Axes()
        if position is None:
            position = [0.13, 0.11, 0.775, 0.815]
            ax.active_outerposition(True)
        else:
            ax.active_outerposition(False)
        ax.set_position(position)
        if not outerposition is None:
            ax.set_outerposition(outerposition)
            ax.active_outerposition(True)

        return ax
Esempio n. 8
0
    def subplot(self, nrows, ncols, plot_number, **kwargs):
        """
        Returen a subplot axes positioned by the given grid definition.

        :param nrows, nrows: (*int*) Whree *nrows* and *ncols* are used to notionally spli the 
            figure into ``nrows * ncols`` sub-axes.
        :param plot_number: (*int) Is used to identify the particular subplot that this function
            is to create within the notional gird. It starts at 1, increments across rows first
            and has a maximum of ``nrows * ncols`` .

        :returns: Current axes specified by ``plot_number`` .
        """
        chart = self.getChart()
        chart.setRowNum(nrows)
        chart.setColumnNum(ncols)
        polar = kwargs.pop('polar', False)
        isnew = True
        if isnew:
            polar = kwargs.pop('polar', False)
            if polar:
                ax = PolarAxes()
            else:
                ax = Axes()
            ax.axes.isSubPlot = True        
        else:
            chart.setCurrentPlot(plot_number - 1)  
        position = kwargs.pop('position', None)
        if position is None:
            if isnew:
                if isinstance(plot_number, (list, tuple)):
                    i = 0
                    for pnum in plot_number:
                        pnum -= 1
                        rowidx = pnum / ncols
                        colidx = pnum % ncols
                        width = 1. / ncols
                        height = 1. / nrows                    
                        x = width * colidx
                        y = 1. - height * (rowidx + 1)
                        if i == 0:
                            minx = x
                            miny = y
                            maxx = x + width
                            maxy = y + height
                        else:
                            minx = min(x, minx)
                            miny = min(y, miny)
                            maxx = max(x + width, maxx)
                            maxy = max(y + height, maxy)
                        i += 1
                    x = minx
                    y = miny
                    width = maxx - minx
                    height = maxy - miny
                else:
                    plot_number -= 1
                    rowidx = plot_number / ncols
                    colidx = plot_number % ncols
                    width = 1. / ncols
                    height = 1. / nrows
                    x = width * colidx
                    y = 1. - height * (rowidx + 1)
                ax.set_position([x, y, width, height])
                ax.set_outerposition([x, y, width, height])
                ax.active_outerposition(True)
        else:
            ax.set_position(position)
            ax.active_outerposition(False)
        outerposition = kwargs.pop('outerposition', None)
        if not outerposition is None:
            ax.set_outerposition(outerposition)
            ax.active_outerposition(True)

        if isinstance(ax, MapAxes):
            self.__set_axesm(ax, **kwargs)
        else:
            self.__set_axes(ax, **kwargs)

        if isnew:
            chart.addPlot(ax.axes)
            chart.setCurrentPlot(chart.getPlots().size() - 1)

        return ax
Esempio n. 9
0
 def __create_axes(self, *args, **kwargs):
     """
     Create an axes.
     
     :param position: (*list*) Optional, axes position specified by *position=* [left, bottom, width
         height] in normalized (0, 1) units. Default is [0.13, 0.11, 0.775, 0.815].
     :param outerposition: (*list*) Optional, axes size and location, including labels and margin.
     
     :returns: The axes.
     """        
     if len(args) > 0:
         position = args[0]
     else:
         position = kwargs.pop('position', None)    
     outerposition = kwargs.pop('outerposition', None)
     axestype = kwargs.pop('axestype', 'cartesian')
     polar = kwargs.pop('polar', False)
     if polar:
         axestype = 'polar'
     if axestype == 'polar':
         ax = PolarAxes()
     elif axestype == 'map':
         ax = MapAxes()
     elif axestype == '3d':
         ax = Axes3D()
     else:
         ax = Axes()
     if position is None:
         position = [0.13, 0.11, 0.775, 0.815]
         ax.active_outerposition(True)
     else:        
         ax.active_outerposition(False)        
     ax.set_position(position)   
     if not outerposition is None:
         ax.set_outerposition(outerposition)
         ax.active_outerposition(True)
     
     return ax