Factorize the selection of dataseries.

Reduce slightly code redundancy by using a helper function to select
the dataseries to plot for each subtrack.
master
Damien Goutte-Gattat 3 years ago
parent cd5d5eba36
commit 4d880a2db3
  1. 18
      incenp/plotting/scatter.py

@ -102,11 +102,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
testset = []
for subtrack in subtracks:
if subtrack is None:
subset = data.loc[:, column].dropna()
else:
level = subtrackname if data.index.nlevels > 1 else None
subset = data.xs(subtrack, level=level).loc[:, column].dropna()
subset = _get_dataseries(data, column, subtrack, subtrackname)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
j += 1
@ -124,7 +120,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
if isinstance(columns, list) and subtrackcolumns:
# Columns as subtracks
for column in columns:
subset = data.xs(track, level=trackname).loc[:, column].dropna()
subset = _get_dataseries(data, column, track, trackname)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
j += 1
@ -133,7 +129,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
indexer = [track, subtrack] if subtrack else [track]
level = [trackname, subtrackname] if subtrack else [trackname]
subset = data.xs(indexer, level=level).loc[:, columns].dropna()
subset = _get_dataseries(data, columns, indexer, level=level)
testset.append(subset)
scatterplot_subtrack(ax, subset, i, j, n, colors[j % n], width, min_sep)
j += 1
@ -147,6 +143,14 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
ax.set_xticklabels(labels)
def _get_dataseries(data, column, indexer, level):
if indexer:
if data.index.nlevels == 1:
level = None
data = data.xs(indexer, level=level)
return data.loc[:, column].dropna()
def _do_test(ax, testset, testfunc, n_track, max_subtrack):
pvalue = testfunc(testset[0], testset[1])
if pvalue:

Loading…
Cancel
Save