start to implement texenv filter for pictures
This commit is contained in:
parent
efcc647b3a
commit
0c33f5322c
32
notes_tools/generate_bilan/filters.py
Normal file
32
notes_tools/generate_bilan/filters.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
from uuid import uuid4
|
||||
from path import Path
|
||||
|
||||
def includegraphic(fig_ax, 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
|
||||
|
||||
"""
|
||||
fig, ax = fig_ax
|
||||
if prefix:
|
||||
filename = "{}_{}.pdf".format(prefix, str(uuid4())[:8])
|
||||
else:
|
||||
filename = "{}.pdf".format(str(uuid4())[:8])
|
||||
path_to_file = Path(path)
|
||||
path_to_file.mkdir_p()
|
||||
fig.savefig(path_to_file/filename)
|
||||
return "\includegraphic[scale={sc}]{{{f}}}".format(sc = scale, f=path_to_file/filename)
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
@ -2,6 +2,7 @@
|
||||
# encoding: utf-8
|
||||
|
||||
import jinja2, os
|
||||
from .filters import includegraphic
|
||||
|
||||
__all__ = ["texenv"]
|
||||
|
||||
@ -24,25 +25,8 @@ texenv = jinja2.Environment(
|
||||
|
||||
# Filters
|
||||
|
||||
def do_calculus(steps, name = "A", sep = "=", end = "", joining = " \\\\ \n"):
|
||||
"""Display properly the calculus
|
||||
texenv.filters['includegraphic'] = includegraphic
|
||||
|
||||
Generate this form string:
|
||||
"name & sep & a_step end joining"
|
||||
|
||||
:param steps: list of steps
|
||||
:returns: latex string ready to be endbeded
|
||||
|
||||
|
||||
"""
|
||||
|
||||
ans = joining.join([name + " & " + sep + " & " + str(s) + end for s in steps])
|
||||
return ans
|
||||
|
||||
texenv.filters['calculus'] = do_calculus
|
||||
|
||||
from random import shuffle
|
||||
texenv.filters['shuffle'] = shuffle
|
||||
|
||||
|
||||
|
||||
|
@ -61,12 +61,15 @@ def radar_graph(labels = [], values = [], optimum = []):
|
||||
N = len(labels)
|
||||
theta = _radar_factory(N)
|
||||
max_val = max(max(optimum), max(values))
|
||||
|
||||
fig = plt.figure(figsize=(3,3))
|
||||
ax = fig.add_subplot(1, 1, 1, projection='radar')
|
||||
|
||||
ax.plot(theta, values, color='k')
|
||||
ax.plot(theta, optimum, color='r')
|
||||
ax.set_varlabels(labels)
|
||||
plt.show()
|
||||
return fig, ax
|
||||
#plt.show()
|
||||
#plt.savefig("radar.png", dpi=100)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user