Commit 74b2b965 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Improve error reporting to user.

parent 820d3594
......@@ -95,32 +95,32 @@ def graph_mpl():
# decode the graph configuration
kwargs = json.loads(graph.plot)
except (TypeError, ValueError) as e:
return INLINE_ALERT % ("Error", e)
# extract keyword which are not arguments of the DataFrame.plot method
plt_cfg = Storage()
for k in PLT_KEYS:
plt_cfg[k] = kwargs.pop(k, None)
# generate the plot using a specific set of columns
df = report.to_df()
if plt_cfg.index:
ax = df.ix[:,plt_cfg.index].plot(**kwargs)
# generate a plot using all columns of the DataFrame
else:
ax = df.T.plot(**kwargs)
# extract keyword which are not arguments of the DataFrame.plot method
plt_cfg = Storage()
for k in PLT_KEYS:
plt_cfg[k] = kwargs.pop(k, None)
# generate the plot using a specific set of columns
df = report.to_df()
if plt_cfg.index:
ax = df.ix[:,plt_cfg.index].plot(**kwargs)
# generate a plot using all columns of the DataFrame
else:
ax = df.T.plot(**kwargs)
except (IndexError, TypeError, ValueError) as e:
return INLINE_ALERT % ("Error", e)
# activate minor ticks
ax.minorticks_on()
# set x / y label(s)
if plt_cfg.xlabel:
ax.set_xlabel(plt_cfg.xlabel)
ax.set_xlabel(plt_cfg.xlabel, x=1, horizontalalignment='right')
if plt_cfg.ylabel:
ax.set_ylabel(plt_cfg.ylabel)
ax.set_ylabel(plt_cfg.ylabel, y=1, horizontalalignment='right')
# push legend on the top outside the plot
# from http://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot
......@@ -138,7 +138,8 @@ def graph_mpl():
fig = ax.get_figure()
fig.savefig(fi, format='svg')
fig.clear()
matplotlib.pyplot.close(fig)
data = fi.getvalue()
fi.close()
......
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