44 lines
1.1 KiB
Python
44 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
from uuid import uuid4
|
|
from path import Path
|
|
import logging
|
|
logger = logging.getLogger("generate_bilan")
|
|
|
|
def includegraphics(fig_ax, document_path="./", fig_path="fig/",
|
|
prefix="", scale=1):
|
|
""" Jinja2 filter which save the figure and return latex includegraphic to display it.
|
|
|
|
:param fig_ax: TODO
|
|
:param path: TODO
|
|
:param prefix: TODO
|
|
:param scale: TODO
|
|
:returns: TODO
|
|
|
|
"""
|
|
try:
|
|
fig, ax = fig_ax
|
|
except TypeError:
|
|
ax = fig_ax
|
|
fig = ax.figure
|
|
|
|
if prefix:
|
|
filename = "{}_{}.pdf".format(prefix, str(uuid4())[:8])
|
|
else:
|
|
filename = "{}.pdf".format(str(uuid4())[:8])
|
|
|
|
path_to_file = Path(document_path/fig_path)
|
|
path_to_file.mkdir_p()
|
|
|
|
fig.savefig(path_to_file/filename)
|
|
logger.info("Graphique {} sauvé à {}".format(filename, path_to_file))
|
|
return "\includegraphics[scale={sc}]{{{f}}}".format(sc = scale,
|
|
f=Path(fig_path)/filename)
|
|
|
|
|
|
# -----------------------------
|
|
# Reglages pour 'vim'
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
# cursor: 16 del
|