Commit 56fb315c authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update matplotlib_tools and lbfr_report to add pages showing funding status.

parent d8893cfb
......@@ -34,22 +34,121 @@ def create_pdf(base):
return PdfPages(fn)
def header_footer(fig, title):
def header_footer(fig, title, timestamp=False):
"""write the header_footer and the footer.
Args:
ax (matplotlib.Figure):
title (str):
timestamp (bool):
"""
msg = NOW.strftime("%b %d, %Y %H:%M\nday %j -- week %W")
fig.text(0.05, 0.9, title, fontsize=14)
fig.text(0.94, 0.89, msg, fontsize=8, horizontalalignment='right')
if timestamp:
msg = NOW.strftime("%b %d, %Y %H:%M\nday %j -- week %W")
fig.text(0.94, 0.89, msg, fontsize=8, horizontalalignment='right')
fig.text(0.94, 0.04, fig.number, fontsize=10, horizontalalignment='right')
def plot_references(ax, lines, values, xpos, stacked=False):
"""Plot reference markers.
Args:
ax (matplotlib.Axes):
lines (list):
values (list): reference value per line
xpos (float):
stacked (bool)
"""
legend = ax.get_legend()
texts = [el.get_text() for el in legend.get_texts()]
value = 0.
mycolor = "black"
for line in lines:
i = texts.index(line)
if stacked:
value += values[i]
else:
value = values[i]
ax.plot(xpos,
value,
color=mycolor,
marker="<",
markeredgecolor=mycolor,
markersize=5,
transform=ax.transData)
def plot_values(ax, series, fmt="%.0f",
fontsize=8.,
maxseries=None,
percentage=0.10,
xoffset=0,
yoffset=-10,
zero=1E-05,
**kwargs):
"""plot values in bar graph.
Args:
ax (matplotlib.Axes):
series (pandas.Series):
fmt (str):
fontsize (float): fontsize for the text.
maxseries (float): maximum of the serie. The maximum of the serie is
computed by the function and used to determined the threshld.
In some case, it is usefull to specified a value.
percentage (float): yoffset is applied if value is a threshold.
The threshold is computed as percentage*max(series).
Otherwise the value is written above the bar.
xoffset (float): offset with respect to the center of the bar in
data coordinate.
yoffset (int): offset of the text with respect to the top of the bar
in the display coordinate.
zero (float): value below the threhols is not displayed
keyward arguments:
those of the matplotlib.text.Text
"""
ndata = len(series)
# fontsize depend on the number of data
fsize = (fontsize if ndata <= 15 else fontsize * sqrt(15. / ndata))
default = dict(color="0.4", fontsize=fsize, horizontalalignment="center")
default.update(kwargs)
# trans formation go to frma the transData to the display coordinate
# and vice versa
ftrans = ax.transData.transform
finv = ax.transData.inverted().transform
# plot values
if maxseries is None:
maxseries = max(series)
cut = round( maxseries * percentage)
for i in xrange(ndata):
value = series.iloc[i]
if value < zero:
continue
yoff = (yoffset if value > cut else 2)
i, y = ftrans((i, value))
i, y = finv((i, y+yoff))
i += xoffset
ax.text(i, y, fmt % value, **default)
def style():
"""Define the matplotlib style, namely font size, line width, etc.
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment