Fix formatting.

Right-trim white lines.
master
Damien Goutte-Gattat 3 years ago
parent 6838f2a5f1
commit f6f9652813
  1. 12
      incenp/plotting/bar.py
  2. 40
      incenp/plotting/scatter.py
  3. 18
      incenp/plotting/util.py

@ -32,7 +32,7 @@ def get_subtrack_offset(n_subtrack, max_subtrack, width):
:param The width of a single subtrack
:return: The offset to apply
"""
total_width = max_subtrack * width
base_offset = -total_width / 2
subtrack_offset = width * n_subtrack
@ -59,19 +59,19 @@ def barplot(ax, data, column, tracks, subtracks=[None], subtrackname=1,
each subtrack)
:param width: The width of a single subtrack:
"""
for s, subtrack in enumerate(subtracks):
if subtrack is not None:
level = subtrackname if data.index.nlevels > 1 else None
subset = data.xs(subtrack, level=level).loc[tracks, :]
else:
subset = data.loc[tracks, :]
x = _arange(len(subset))
ax.set_xticks(x)
xoff = x + get_subtrack_offset(s, len(subtracks), width)
rects = ax.bar(xoff, subset[column], width, color=colors[s])
if ncolumn:
for i, rect in enumerate(rects):
height = rect.get_height()
@ -82,6 +82,6 @@ def barplot(ax, data, column, tracks, subtracks=[None], subtrackname=1,
textcoords='offset points',
ha='center', va='center',
fontsize='xx-small')
ax.set_xticklabels(tracks)

@ -39,13 +39,13 @@ def scatterplot_subtrack(ax, data, n_track, n_subtrack, max_subtrack,
than this parameter, they will be considered to belong on the
same rank and will be distributed along the X axis
"""
offset = n_track * max_subtrack + n_subtrack
xs = xdistr(data.values, width, center=True, min_sep=min_sep, offset=offset)
ax.plot(xs, data.values, color + '.')
ax.hlines(data.mean(), offset - .5, offset + .5, color)
def scatterplot(ax, data, columns, subtrackcolumns=False,
tracks=[None], trackname=0,
subtracks=[None], subtrackname=1,
@ -75,7 +75,7 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
exactly two subtracks, the function will be called for each
track and the signficance will be displayed on top of the track
"""
# Get number of subtracks and track labels
if isinstance(columns, list):
if subtrackcolumns:
@ -92,31 +92,31 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
# Use tracks and subtracks as specified
n = len(subtracks) + 1
labels = tracks
i = 0
if isinstance(columns, list) and not subtrackcolumns:
# Columns as tracks
for column in columns:
j = 0
testset = []
for subtrack in subtracks:
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
if testfunc and len(subtracks) == 2:
_do_test(ax, testset, testfunc, i, n)
i += 1
else:
for track in tracks:
j = 0
testset = []
if isinstance(columns, list) and subtrackcolumns:
# Columns as subtracks
for column in columns:
@ -128,29 +128,29 @@ def scatterplot(ax, data, columns, subtrackcolumns=False,
for subtrack in subtracks:
indexer = [track, subtrack] if subtrack else [track]
level = [trackname, subtrackname] if subtrack else [trackname]
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
if testfunc and len(testset) == 2:
_do_test(ax, testset, testfunc, i, n)
i += 1
ax.set_xticks([(.5 * (n - 2)) + n * i for i in range(len(labels))])
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:
@ -158,4 +158,4 @@ def _do_test(ax, testset, testfunc, n_track, max_subtrack):
offset = n_track * max_subtrack
ax.hlines(y, offset - .5, offset + 1.5)
ax.text(offset + .5, y, get_stars(pvalue), ha='center', va='bottom')

@ -35,15 +35,15 @@ def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=-.05):
it is interpreted as a fraction of the span of values
:return: An array of x coordinates
"""
dist = {}
spent = {}
xcoords = []
if min_sep < 0:
min_sep = (max(values) - min(values)) * -min_sep
values = [int(i / min_sep) for i in values]
# Get the distribution of values
for v in values:
if v in dist:
@ -51,13 +51,13 @@ def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=-.05):
else:
dist[v] = 1
spent[v] = 0
# Now proceeds
for v in values:
# Compute step to distribute the values on the specified width
step = width / max(even_max, dist[v])
if not center:
x = offset + step * spent[v]
elif spent[v] % 2 == 0:
@ -67,15 +67,15 @@ def xdistr(values, width, offset=0, even_max=10, center=False, min_sep=-.05):
else:
# Draw the next point on the left of offset
x = offset - (step / 2) * (spent[v] + 1)
# If there is an even number of points in that rank,
# shift all points by a half-step
if dist[v] % 2 == 0:
x += step / 2
spent[v] += 1
xcoords.append(x)
return xcoords

Loading…
Cancel
Save