Exemple #1
0
    def create_top_stacked_axes(self,heights=(1.)):
        """
        Create several axes for subplot on top of each other

        Args:
            heights (iterable):  relative height e.g.
                                 heights = [.2,.1,.6] will give axes using this amount of
                                 space
        """
        assert sum(heights) <= 1., "heights must be in relative heights"
    
        cfg = get_config_item("canvas")
        left = cfg["leftpadding"]
        right = cfg["rightpadding"]
        bot  = cfg["bottompadding"]
        top  = cfg["toppadding"]
        width = 1. - left - right
        height = 1. - top - bot
        
        heights = [height*h for h in heights]
        heights.reverse()
        Logger.debug("Using heights {0}".format(heights.__repr__()))
        abs_bot = 0 +bot     
        axes = [p.axes([left,abs_bot,width,heights[0]])]
        restheights = heights[1:]
        abs_bot = bot + heights[0]
        for h in restheights:
            theaxes = p.axes([left,abs_bot,width,h])
            p.setp(theaxes.get_xticklabels(), visible=False)
            axes.append(theaxes)
            abs_bot += h
    
        self.axes = axes
Exemple #2
0
    def save(self,path,name,endings=("pdf","png"),**kwargs):
        """
        Calls pylab.savefig for all endings

        Args:
            path (str): path to savefile
            name (str): filename to save
            endings (tuple): for each name in endings, a file is save

        Keyword Args:
            all keyword args will be passed to pylab.savefig

        Returns:
            str: The full path to the the saved file
        """
        if not kwargs:
            kwargs = get_config_item("savefig")

        self.savekwargs = kwargs
        self.savekwargs.update({'path' : path,'name' : name, 'endings' : endings})
        for ending in endings:
            filename = os.path.join(path,name + '.' + ending)
            self.figure.savefig(filename,format=ending,**kwargs)
            if ending == "png":
                self.png_filename = filename
        return self.png_filename