Commit afab8ae0 authored by Theophile GENTILHOMME's avatar Theophile GENTILHOMME

Bins can now be givens for each histogram in the figure

parent b2dc1d84
Pipeline #19454 passed with stage
in 42 minutes and 37 seconds
......@@ -174,16 +174,19 @@ def n_bins_option(**kwargs):
def callback(ctx, param, value):
if value is None:
value = 'auto'
elif value < 2:
raise click.BadParameter(
'Number of bins must be greater than 1'
, ctx=ctx
)
else:
tmp = value.split(',')
try:
value = [int(i) if i != 'auto' else i for i in tmp]
except Exception:
raise click.BadParameter('Incorrect number of bins inputs')
ctx.meta['n_bins'] = value
return value
return click.option(
'-b', '--nbins', type=INT, default=None,
help='The number of bins in the histogram(s). Default: `auto`',
'-b', '--nbins', type=click.STRING, default='auto',
help='The number of bins for the different histograms in the '
' figure, seperated by commas. For example, if three histograms '
'are in the plots, input something like `100,auto,50`',
callback=callback, **kwargs)(func)
return custom_n_bins_option
......
......@@ -520,7 +520,7 @@ class Hist(PlotBase):
''' Functional base class for histograms'''
def __init__(self, ctx, scores, evaluation, func_load):
super(Hist, self).__init__(ctx, scores, evaluation, func_load)
self._nbins = None if 'n_bins' not in ctx.meta else ctx.meta['n_bins']
self._nbins = [] if 'n_bins' not in ctx.meta else ctx.meta['n_bins']
self._thres = None if 'thres' not in ctx.meta else ctx.meta['thres']
self._show_dev = ((not self._eval) if 'show_dev' not in ctx.meta else\
ctx.meta['show_dev']) or not self._eval
......@@ -621,9 +621,11 @@ class Hist(PlotBase):
) if self._thres is None else self._thres[idx]
return dev_neg, dev_pos, eval_neg, eval_pos, threshold
def _density_hist(self, scores, **kwargs):
def _density_hist(self, scores, n, **kwargs):
n, bins, patches = mpl.hist(
scores, density=True, bins=self._nbins, **kwargs
scores, density=True,
bins='auto' if len(self._nbins) <= n else self._nbins[n],
**kwargs
)
return (n, bins, patches)
......@@ -638,8 +640,11 @@ class Hist(PlotBase):
def _setup_hist(self, neg, pos):
''' This function can be overwritten in derived classes'''
self._density_hist(
pos[0], label='Positives', alpha=0.5, color='C0'
neg[0], n=0,
label='Negatives', alpha=0.5, color='C3'
)
self._density_hist(
neg[0], label='Negatives', alpha=0.5, color='C3'
pos[0], n=1,
label='Positives', alpha=0.5, color='C0'
)
......@@ -132,14 +132,14 @@ def test_hist():
with runner.isolated_filesystem():
result = runner.invoke(commands.hist, ['--no-evaluation', '--criterion', 'hter',
'--output', 'HISTO.pdf', '-b',
30, dev1, dev2])
'30,100', dev1, dev2])
if result.output:
click.echo(result.output)
assert result.exit_code == 0, (result.exit_code, result.output)
with runner.isolated_filesystem():
result = runner.invoke(commands.hist, ['--criterion', 'eer','--output',
'HISTO.pdf', '-b', 30,
'HISTO.pdf', '-b', '30,20',
dev1, test1, dev2, test2])
if result.output:
click.echo(result.output)
......@@ -159,7 +159,7 @@ def test_evaluate():
with runner.isolated_filesystem():
result = runner.invoke(
commands.evaluate, ['--no-evaluation', '--output', 'my_plots.pdf', '-b',
30, '-n', 300, dev1, dev2])
'30,69', '-n', 300, dev1, dev2])
assert result.exit_code == 0, (result.exit_code, result.output)
with runner.isolated_filesystem():
......
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