logging_plotting.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:merlin 作者: CSTR-Edinburgh 项目源码 文件源码
def save_plot(self,plot_name,**kwargs):
        logger = logging.getLogger("plotting")
        if plot_name not in self.plots:
            logger.warn('Tried to generate a plot called %s that does not exist' % plot_name)
            # raise an exception here?
        else:
            # # the filename to save to is known by the handler, which needs to be assigned to this logger
            # # look at the handlers attached to this logger instance
            # ph=None
            # for h in self.handlers:
            #     # we want an instance of a PlotHandler - we'll take the first one we find
            #     # (behaviour will be unpredictable if there is more than one handler of this type)
            #     if isinstance(h,PlotHandler):
            #         ph=h
            #         break
            # if ph:
            # TO DO - need to be sure of safe file names
            if not os.path.isdir(self.plot_path):
                os.makedirs(self.plot_path)
            filename = self.plot_path + "/" + string.replace(plot_name, " ", "_") + ".pdf"
            logger.info('Generating a plot in file %s' % filename)
            self.plots[plot_name].generate_plot(filename,**kwargs)
            # else:
            #     logger.warn('No handler of type PlotHandler is attached to this logger - cannot save plots')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号