[variability] fix some z-ordering issues, plot size, and excess .0 in labels

This commit is contained in:
jan 2025-12-30 02:45:33 -08:00
parent 4ba0eb09e8
commit f0213824d9

View File

@ -90,7 +90,7 @@ def variability_plot(
y_ratios = [mainplot_ratios[1]] + get_label_y_ratios(groups, vert_groups, size_lists)
# Build the figure and all axes
fig = pyplot.figure()
fig = pyplot.figure(figsize=(16, 9))
gs = gridspec.GridSpec(
nrows = 1 + len(groups),
ncols = 2,
@ -117,14 +117,16 @@ def variability_plot(
dotprops = {}
dotprops.setdefault('alpha', 0.7)
dotprops.setdefault('color', 'black')
dotprops.setdefault('zorder', 5)
_dotplt = ax.scatter(x_data, y_data, s=numpy.ones_like(y_data), **dotprops)
if boxprops:
if not isinstance(boxprops, dict):
boxprops = {}
boxprops.setdefault('showfliers', False)
boxprops.setdefault('medianprops', dict(linewidth=3, color='darkred', alpha=0.8))
boxprops.setdefault('boxprops', dict(linewidth=0.5, color='black'))
boxprops.setdefault('whiskerprops', dict(linewidth=0.5, color='black'))
boxprops.setdefault('medianprops', dict(linewidth=3, color='darkred', alpha=0.5, zorder=2))
boxprops.setdefault('boxprops', dict(linewidth=0.5, color='black', zorder=3))
boxprops.setdefault('whiskerprops', dict(linewidth=0.5, color='black', zorder=3))
boxprops.setdefault('zorder', 3)
_boxplt = ax.boxplot(y_lists, positions=range(num_dsets), **boxprops)
if meanprops:
means = [yl.mean() for yl in y_lists]
@ -140,6 +142,7 @@ def variability_plot(
meanprops.setdefault('color', 'blue')
meanprops.setdefault('alpha', 0.8)
meanprops.setdefault('linewidth', 0.5)
meanprops.setdefault('zorder', 3)
_meanplt = ax.plot(xy[:, 0], xy[:, 1], **meanprops)
@ -211,8 +214,8 @@ def variability_plot(
ax.set_xticklabels([], minor=False)
ax.set_xticklabels([], minor=True)
ax.tick_params('x', which='both', bottom=False)
ax.grid(alpha=0.2, which='minor')
ax.grid(alpha=1, which='major')
ax.grid(alpha=0.2, which='minor', zorder=0)
ax.grid(alpha=1, which='major', zorder=0)
ax.set_ylabel(data_col)
ax.set_title(data_col)
ax.yaxis.set_minor_locator(ticker.AutoMinorLocator())
@ -284,7 +287,8 @@ def get_label_stack(df_groups: polars.DataFrame, groups: Sequence[str], wrap_fn:
label_row = []
for row in spans.to_dicts():
# df row is plot column
text_value = wrap_fn(str(row[level]))
rl = row[level]
text_value = wrap_fn(rl) if isinstance(rl, str) else wrap_fn(str(rl).removesuffix('.0'))
label_row.append((row['xmin'], row['xmax'], text_value))
label_stack.append(label_row)
return label_stack