def make_python_fig(self, code: str,
exts: Tuple[str, ...]=('pdf', 'svg'),
tight_layout=True) -> str:
hashsum = hashlib.md5(code.encode('utf8')).hexdigest()
prefix = hashsum[:2]
path = os.path.join(self.figures_dir, prefix, hashsum)
needfigure = False
for ext in exts:
if not os.path.isfile(os.path.join(
path, self.default_figname + "." + ext)):
needfigure = True
break
if needfigure:
make_sure_path_exists(path)
gl = self.pythonfigure_globals
plt.close()
exec(code, gl)
if tight_layout:
plt.tight_layout()
for ext in exts:
plt.savefig(os.path.join(
path, self.default_figname + "." + ext))
return os.path.join(prefix, hashsum)
评论列表
文章目录