Commit 4816ae3f authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

[script][commands,common_options,figure] Allow to pass titles for all

plots

Before only one title could be changed even when two plots where in the
figure and title was augmented with (development/evaluation). Now the
titles can be entirely defined.
parent 2971f262
Pipeline #20777 passed with stage
in 30 minutes and 28 seconds
......@@ -44,7 +44,7 @@ def metrics(ctx, scores, evaluation, **kwargs):
@click.command()
@common_options.scores_argument(nargs=-1)
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt=None)
......@@ -89,7 +89,7 @@ def roc(ctx, scores, evaluation, **kwargs):
@click.command()
@common_options.scores_argument(nargs=-1)
@common_options.output_plot_file_option(default_out='det.pdf')
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt='upper-right')
......@@ -132,7 +132,7 @@ def det(ctx, scores, evaluation, **kwargs):
@click.command()
@common_options.scores_argument(min_arg=1, force_eval=True, nargs=-1)
@common_options.output_plot_file_option(default_out='epc.pdf')
@common_options.title_option()
@common_options.titles_option()
@common_options.legends_option()
@common_options.no_legend_option()
@common_options.legend_loc_option(dflt='upper-center')
......@@ -172,7 +172,6 @@ def epc(ctx, scores, **kwargs):
@common_options.thresholds_option()
@common_options.const_layout_option()
@common_options.print_filenames_option()
@common_options.title_option()
@common_options.legends_option()
@common_options.figsize_option(dflt=None)
@common_options.style_option()
......
......@@ -461,6 +461,25 @@ def title_option(**kwargs):
return custom_title_option
def titles_option(**kwargs):
'''Get the titles option for the different plots'''
def custom_title_option(func):
def callback(ctx, param, value):
if value is not None:
value = value.split(',')
ctx.meta['titles'] = value or []
return value or []
return click.option(
'-ts', '--titles', type=click.STRING, default=None,
help='The titles of the plots seperated by commas. '
'For example, if the figure has two plots, \"MyTitleA,MyTitleB\" '
'is a possible input'
'Provide just a space (-t ' ') to '
'remove the titles from figures.',
callback=callback, **kwargs)(func)
return custom_title_option
def x_label_option(dflt=None, **kwargs):
'''Get the label option for X axis '''
def custom_x_label_option(func):
......
......@@ -294,8 +294,8 @@ class PlotBase(MeasureBase):
self._line_linestyles = ctx.meta.get('line_linestyles', False)
self._linestyles = utils.get_linestyles(
self.n_systems, self._line_linestyles)
self._states = ['Development', 'Evaluation']
self._title = ctx.meta.get('title')
self._titles = ctx.meta.get('titles', []) * 2
self._x_label = ctx.meta.get('x_label')
self._y_label = ctx.meta.get('y_label')
self._grid_color = 'silver'
......@@ -343,12 +343,8 @@ class PlotBase(MeasureBase):
if self._end_setup_plot:
for i in range(self._nb_figs):
fig = mpl.figure(i + 1)
title = self._title
if not self._eval:
title += (" (%s)" % self._states[0])
elif self._split:
title += (" (%s)" % self._states[i])
mpl.title(title if self._title.replace(' ', '') else '')
title = '' if not self._titles else self._titles[i]
mpl.title(title if title.replace(' ', '') else '')
mpl.xlabel(self._x_label)
mpl.ylabel(self._y_label)
mpl.grid(True, color=self._grid_color)
......@@ -382,7 +378,7 @@ class Roc(PlotBase):
def __init__(self, ctx, scores, evaluation, func_load):
super(Roc, self).__init__(ctx, scores, evaluation, func_load)
self._title = self._title or 'ROC'
self._titles = self._titles or ['ROC dev', 'ROC eval']
self._x_label = self._x_label or 'False Positive Rate'
self._y_label = self._y_label or "1 - False Negative Rate"
self._semilogx = ctx.meta.get('semilogx', True)
......@@ -409,7 +405,7 @@ class Roc(PlotBase):
far_values=plot.log_values(self._min_dig or -4),
CAR=self._semilogx,
color=self._colors[idx], linestyle=self._linestyles[idx],
label=self._label('development', dev_file, idx)
label=self._label('dev', dev_file, idx)
)
if self._split:
mpl.figure(2)
......@@ -437,7 +433,7 @@ class Roc(PlotBase):
far_values=plot.log_values(self._min_dig or -4),
CAR=self._semilogx,
color=self._colors[idx], linestyle=self._linestyles[idx],
label=self._label('development', dev_file, idx)
label=self._label('dev', dev_file, idx)
)
......@@ -446,7 +442,7 @@ class Det(PlotBase):
def __init__(self, ctx, scores, evaluation, func_load):
super(Det, self).__init__(ctx, scores, evaluation, func_load)
self._title = self._title or 'DET'
self._titles = self._titles or ['DET dev', 'DET eval']
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 'upper right'
......@@ -514,7 +510,7 @@ class Epc(PlotBase):
super(Epc, self).__init__(ctx, scores, evaluation, func_load)
if self._min_arg != 2:
raise click.UsageError("EPC requires dev and eval score files")
self._title = self._title or 'EPC'
self._titles = self._titles or ['EPC'] * 2
self._x_label = self._x_label or r'$\alpha$'
self._y_label = self._y_label or 'HTER (%)'
self._legend_loc = self._legend_loc or 'upper center'
......@@ -603,9 +599,8 @@ class Hist(PlotBase):
def _get_title(self, idx, dev_file, eval_file):
title = self._legends[idx] if self._legends is not None else None
title = title or self._title or self._title_base
title = '' if self._title is not None and not self._title.replace(
' ', '') else title
title = title or self._title_base
title = '' if title is not None and not title.replace(' ', '') else title
return title or ''
def _plot_legends(self):
......
......@@ -575,8 +575,8 @@ For example, to generate a DET curve from development and evaluation datasets:
.. code-block:: sh
$bob measure det -v --output 'my_det.pdf' dev-1.txt eval-1.txt
dev-2.txt eval-2.txt
$bob measure det -v --output "my_det.pdf" -ts "DetDev1,DetEval1,DetDev2,DetEval2"
dev-1.txt eval-1.txt dev-2.txt eval-2.txt
where `my_det.pdf` will contain DET plots for the two experiments.
......
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