Commit ab1b3573 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

Add options for legends display

parent 7ec523ca
......@@ -46,6 +46,8 @@ def metrics(ctx, scores, evaluation, **kwargs):
@common_options.scores_argument(nargs=-1)
@common_options.title_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt=4)
@common_options.sep_dev_eval_option()
@common_options.output_plot_file_option(default_out='roc.pdf')
@common_options.eval_option()
......@@ -89,6 +91,8 @@ def roc(ctx, scores, evaluation, **kwargs):
@common_options.output_plot_file_option(default_out='det.pdf')
@common_options.title_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt=1)
@common_options.sep_dev_eval_option()
@common_options.eval_option()
@common_options.axes_val_option(dflt=[0.01, 95, 0.01, 95])
......@@ -130,6 +134,8 @@ def det(ctx, scores, evaluation, **kwargs):
@common_options.output_plot_file_option(default_out='epc.pdf')
@common_options.title_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt=9)
@common_options.points_curve_option()
@common_options.const_layout_option()
@common_options.x_label_option()
......@@ -173,6 +179,7 @@ def epc(ctx, scores, **kwargs):
@common_options.linestyles_option()
@common_options.subplot_option()
@common_options.legend_ncols_option()
@common_options.no_legend_option()
@verbosity_option()
@click.pass_context
def hist(ctx, scores, evaluation, **kwargs):
......
......@@ -57,6 +57,14 @@ def scores_argument(min_arg=1, force_eval=False, **kwargs):
return custom_scores_argument
def no_legend_option(dflt=True, **kwargs):
'''Get option flag to say if legend should be displayed or not'''
return bool_option(
'disp-legend', 'dl', 'If set, no legend will be printed.',
dflt=dflt
)
def eval_option(**kwargs):
'''Get option flag to say if eval-scores are provided'''
return bool_option(
......@@ -380,14 +388,14 @@ def figsize_option(dflt='4,3', **kwargs):
return custom_figsize_option
def legend_loc_option(**kwargs):
def legend_loc_option(dflt=0, **kwargs):
'''Get the legend location of the plot'''
def custom_legend_loc_option(func):
def callback(ctx, param, value):
ctx.meta['legend_loc'] = value
return value
return click.option(
'--legend-location', default=0, show_default=True,
'-lc', '--legend-loc', default=dflt, show_default=True,
type=INT, help='The legend location code',
callback=callback, **kwargs)(func)
return custom_legend_loc_option
......
......@@ -275,6 +275,10 @@ class PlotBase(MeasureBase):
self._points = 100 if 'points' not in ctx.meta else ctx.meta['points']
self._split = None if 'split' not in ctx.meta else ctx.meta['split']
self._axlim = None if 'axlim' not in ctx.meta else ctx.meta['axlim']
self._disp_legend = True if 'disp_legend' not in ctx.meta else\
ctx.meta['disp_legend']
self._legend_loc = None if 'legend_loc' not in ctx.meta else\
ctx.meta['legend_loc']
self._min_dig = None
if 'min_far_value' in ctx.meta:
self._min_dig = int(math.log10(ctx.meta['min_far_value']))
......@@ -291,7 +295,7 @@ class PlotBase(MeasureBase):
self._lines_val = []
self._print_fn = True if 'show_fn' not in ctx.meta else\
ctx.meta['show_fn']
self._x_rotation = None if 'x_rotation' not in ctx.meta else \
self._x_rotation = None if 'x_rotation' not in ctx.meta else\
ctx.meta['x_rotation']
if 'style' in ctx.meta:
mpl.style.use(ctx.meta['style'])
......@@ -362,7 +366,8 @@ class PlotBase(MeasureBase):
mpl.xlabel(self._x_label)
mpl.ylabel(self._y_label)
mpl.grid(True, color=self._grid_color)
mpl.legend(loc='best')
if self._disp_legend:
mpl.legend(loc=self._legend_loc)
self._set_axis()
mpl.xticks(rotation=self._x_rotation)
self._pdf_page.savefig(fig)
......@@ -394,6 +399,7 @@ class Roc(PlotBase):
self._title = self._title or 'ROC'
self._x_label = self._x_label or 'False Positive Rate'
self._y_label = self._y_label or "1 - False Negative Rate"
self._legend_loc = self._legend_loc or 4
# custom defaults
if self._axlim is None:
self._axlim = [1e-4, 1.0, 0, 1.0]
......@@ -455,6 +461,7 @@ class Det(PlotBase):
self._title = self._title or 'DET'
self._x_label = self._x_label or 'False Positive Rate'
self._y_label = self._y_label or 'False Negative Rate'
self._legend_loc = self._legend_loc or 1
if self._far_at is not None:
self._trans_far_val = [ppndf(float(k)) for k in self._far_at]
# custom defaults here
......@@ -522,6 +529,7 @@ class Epc(PlotBase):
self._title = self._title or 'EPC'
self._x_label = self._x_label or r'$\alpha$'
self._y_label = self._y_label or 'HTER (%)'
self._legend_loc = self._legend_loc or 9
self._eval = True # always eval data with EPC
self._split = False
self._nb_figs = 1
......@@ -620,10 +628,11 @@ class Hist(PlotBase):
li, la = ax.get_legend_handles_labels()
lines += li
labels += la
mpl.gcf().legend(
lines, labels, fontsize=6, loc='upper center', fancybox=True,
framealpha=0.5, ncol=self._nlegends,
)
if self._disp_legend:
mpl.gcf().legend(
lines, labels, fontsize=6, loc=self._legend_loc, fancybox=True,
framealpha=0.5, ncol=self._nlegends,
)
def _get_neg_pos_thres(self, idx, input_scores, input_names):
neg_list, pos_list, _ = utils.get_fta_list(input_scores)
......
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