Skip to content

Commit

Permalink
fix(eyepy.core): make sure ticklabels match plotted image region for …
Browse files Browse the repository at this point in the history
…EyeEnfac ande EyeBscan plots
  • Loading branch information
Oli4 committed Feb 13, 2023
1 parent 2842424 commit f389f47
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
28 changes: 21 additions & 7 deletions src/eyepy/core/eyebscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,24 @@ def plot(
**layer_kwargs,
)

# Hack to avoid a warning when setting the tick labels later
# Warning: FixedFormatter should only be used together with FixedLocator
ax.set_yticks(ax.get_yticks())
ax.set_xticks(ax.get_xticks())

ax.set_yticklabels((ax.get_yticks() + y_start).astype(int))
ax.set_xticklabels((ax.get_xticks() + x_start).astype(int))
# Make sure tick labels match the image region
y_start = region[0].start if region[0].start is not None else 0
x_start = region[1].start if region[1].start is not None else 0
y_end = region[0].stop if region[0].stop is not None else self.shape[0]
x_end = region[1].stop if region[1].stop is not None else self.shape[1]

# Ticks are not clipped to the image region. Clip them here.
yticks = ax.get_yticks()
yticks = yticks[np.nonzero(
np.logical_and(yticks >= 0, yticks <= y_end - y_start - 1))]
xticks = ax.get_xticks()
xticks = xticks[np.nonzero(
np.logical_and(xticks >= 0, xticks <= x_end - x_start - 1))]

# Set clipped ticks (this is only necessary because we change the labels later)
ax.set_yticks(yticks)
ax.set_xticks(xticks)

# Set labels to ticks + start of the region as an offset
ax.set_yticklabels([str(int(t + y_start)) for t in yticks])
ax.set_xticklabels([str(int(t + x_start)) for t in xticks])
25 changes: 19 additions & 6 deletions src/eyepy/core/eyeenface.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,24 @@ def plot(self,
ax = plt.gca()
ax.imshow(self.data[region], cmap="gray")

ax.set_yticks(ax.get_yticks())
ax.set_xticks(ax.get_xticks())

# Make sure tick labels match the image region
y_start = region[0].start if region[0].start is not None else 0
x_start = region[1].start if region[1].start is not None else 0

ax.set_yticklabels((ax.get_yticks() + y_start).astype(int))
ax.set_xticklabels((ax.get_xticks() + x_start).astype(int))
y_end = region[0].stop if region[0].stop is not None else self.size_y
x_end = region[1].stop if region[1].stop is not None else self.size_x

# Ticks are not clipped to the image region. Clip them here.
yticks = ax.get_yticks()
yticks = yticks[np.nonzero(
np.logical_and(yticks >= 0, yticks <= y_end - y_start - 1))]
xticks = ax.get_xticks()
xticks = xticks[np.nonzero(
np.logical_and(xticks >= 0, xticks <= x_end - x_start - 1))]

# Set clipped ticks (this is only necessary because we change the labels later)
ax.set_yticks(yticks)
ax.set_xticks(xticks)

# Set labels to ticks + start of the region as an offset
ax.set_yticklabels([str(int(t + y_start)) for t in yticks])
ax.set_xticklabels([str(int(t + x_start)) for t in xticks])

0 comments on commit f389f47

Please sign in to comment.