Nearly finished 1st draft of species-specific Thresh-LP invariance figure (WIP).

This commit is contained in:
j-hartling
2026-03-13 17:15:03 +01:00
parent 4f5054c8fd
commit 1516fe6090
19 changed files with 735 additions and 239 deletions

View File

@@ -35,8 +35,7 @@ def letter_subplot(artist, label, x=None, y=None, xref=None, yref=None, ref=None
ha='left', va='bottom', fontsize=16, fontweight='bold', **kwargs):
trans_artist = BboxTransformTo(artist.bbox)
if x is None or y is None:
trans_ref = BboxTransformTo(ref.bbox)
transform = trans_ref + trans_artist.inverted()
transform = BboxTransformTo(ref.bbox) + trans_artist.inverted()
if x is None:
x = transform.transform([xref, 0])[0]
if y is None:
@@ -102,15 +101,33 @@ def ylabel(ax, label, x=-0.2, y=None, fontsize=20, transform=None, **kwargs):
ax.yaxis.set_label_coords(x, y, transform=transform)
return None
def super_xlabel(label, fig, high_ax, low_ax, y=0.005, **kwargs):
x = (low_ax.get_position().x0 + high_ax.get_position().x1) / 2
fig.supxlabel(label, x=x, y=y, **kwargs)
return None
def super_xlabel(label, fig, left_ax, right_ax, y=0.005,
left_fig=None, right_fig=None, **kwargs):
left_x = left_ax.get_position().x0
right_x = right_ax.get_position().x1
if left_fig is not None or right_fig is not None:
trans_fig = BboxTransformTo(fig.bbox)
if left_fig is not None:
transform = BboxTransformTo(left_fig.bbox) + trans_fig.inverted()
left_x = transform.transform((left_x, 0))[0]
if right_fig is not None:
transform = BboxTransformTo(right_fig.bbox) + trans_fig.inverted()
right_x = transform.transform((right_x, 0))[0]
return fig.supxlabel(label, x=(left_x + right_x) / 2, y=y, **kwargs)
def super_ylabel(label, fig, high_ax, low_ax, x=0.005, **kwargs):
y = (low_ax.get_position().y0 + high_ax.get_position().y1) / 2
fig.supylabel(label, x=x, y=y, **kwargs)
return None
def super_ylabel(label, fig, low_ax, high_ax, x=0.005,
high_fig=None, low_fig=None, **kwargs):
low_y = high_ax.get_position().y0
high_y = low_ax.get_position().y1
if low_fig is not None or high_fig is not None:
trans_fig = BboxTransformTo(fig.bbox)
if low_fig is not None:
transform = BboxTransformTo(low_fig.bbox) + trans_fig.inverted()
low_y = transform.transform((0, low_y))[1]
if high_fig is not None:
transform = BboxTransformTo(high_fig.bbox) + trans_fig.inverted()
high_y = transform.transform((0, high_y))[1]
return fig.supylabel(label, x=x, y=(low_y + high_y) / 2, **kwargs)
def plot_line(ax, time, signal, ymin=None, ymax=None, xmin=None, xmax=None,
xpad=None, ypad=0.05, yloc=None, xloc=None, **kwargs):
@@ -170,18 +187,20 @@ def strip_zeros(num, right_digits=5):
return left
def time_bar(ax, dur, y0=0.9, y1=0.95, xshift=0.5, parent=None, transform=None, **kwargs):
t0, t1 = ax.get_xlim()
offset = (t1 - t0 - dur) * xshift
x0 = t0 + offset
x1 = x0 + dur
if parent is None:
t_lims = ax.get_xlim()
span = t_lims[1] - t_lims[0]
if parent is not None or transform is not None:
if transform is None:
transform = BboxTransformTo(parent.bbox)
kwargs['transform'] = transform
transform = ax.transData + transform.inverted()
x0 = transform.transform((t_lims[0], 0))[0]
x1 = transform.transform((t_lims[0] + dur, 0))[0]
dur = x1 - x0
span = 1
elif parent is None:
parent = ax
if transform is None:
transform = BboxTransformTo(parent.bbox)
if transform is not ax.transData:
trans = ax.transData + transform.inverted()
x0 = trans.transform((x0, 0))[0]
x1 = trans.transform((x1, 0))[0]
parent.add_artist(plt.Rectangle((x0, y0), x1 - x0, y1 - y0,
transform=transform, **kwargs))
x0 = (span - dur) * xshift
x1 = x0 + dur
parent.add_artist(plt.Rectangle((x0, y0), dur, y1 - y0, **kwargs))
return None