Skip to content

Commit

Permalink
FIX XAxisMixin: correct x-min and x-max for line plot
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Feb 2, 2017
1 parent a91456a commit a855c49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion eelbrain/_data_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -6955,7 +6955,7 @@ def _diminfo(self):
return str(self.name)

def _axis_im_extent(self):
"extent for im plots"
"extent for im plots; needs to extend beyond end point locations"
return -0.5, len(self) - 0.5

def _axis_format(self, scalar, label):
Expand Down
40 changes: 24 additions & 16 deletions eelbrain/plot/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,9 @@ class XAxisMixin(object):
Axes that should be managed by the mixin.
xlim : tuple of 2 scalar
Initial x-axis display limits.
im : bool
Plot displays an im, i.e. the axes limits need to extend beyond the
dimension endpoints by half a step (default False).
Notes
-----
Expand All @@ -2045,10 +2048,15 @@ class XAxisMixin(object):
- ``f``: x-axis zoom in (reduce x axis range)
- ``d``: x-axis zoom out (increase x axis range)
"""
def __init__(self, epochs, xdim, xlim=None, axes=None):
extent = tuple(e.get_dim(xdim)._axis_im_extent() for e in chain(*epochs))
self.__xmin = min(e[0] for e in extent)
self.__xmax = max(e[1] for e in extent)
def __init__(self, epochs, xdim, xlim=None, axes=None, im=False):
dims = tuple(e.get_dim(xdim) for e in chain(*epochs))
if im:
dim_extent = tuple(dim._axis_im_extent() for dim in dims)
self.__xmin = min(e[0] for e in dim_extent)
self.__xmax = max(e[1] for e in dim_extent)
else:
self.__xmin = min(dim[0] for dim in dims)
self.__xmax = max(dim[-1] for dim in dims)
self.__axes = axes or self._axes
self.__vspans = []
self._register_key('f', self.__on_zoom_plus)
Expand All @@ -2063,14 +2071,16 @@ def __init__(self, epochs, xdim, xlim=None, axes=None):
def _get_xlim(self):
return self.__axes[0].get_xlim()

def __animate(self, vmin, vmin_d, vmax, vmax_d):
def __animate(self, vmin, vmin_dst, vmax, vmax_dst):
print(vmin_dst, vmax_dst)
n_steps = int(0.1 // self._last_draw_time)
if n_steps <= 1:
self.set_xlim(vmin + vmin_d, vmax + vmax_d)
else:
for i in xrange(1, n_steps + 1):
if n_steps > 1:
vmin_d = vmin_dst - vmin
vmax_d = vmax_dst - vmax
for i in xrange(1, n_steps):
x = i / n_steps
self.set_xlim(vmin + x * vmin_d, vmax + x * vmax_d)
self.set_xlim(vmin_dst, vmax_dst)

def __on_beginning(self, event):
left, right = self._get_xlim()
Expand All @@ -2084,29 +2094,27 @@ def __on_end(self, event):

def __on_zoom_plus(self, event):
left, right = self._get_xlim()
d = right - left
self.__animate(left, d / 4., right, -d / 4.)
d = (right - left) / 4.
self.__animate(left, left + d, right, right - d)

def __on_zoom_minus(self, event):
left, right = self._get_xlim()
d = right - left
new_left = max(self.__xmin, left - (d / 2.))
new_right = min(self.__xmax, new_left + 2 * d)
self.__animate(left, new_left - left, right, new_right - right)
self.__animate(left, new_left, right, new_right)

def __on_left(self, event):
left, right = self._get_xlim()
d = right - left
new_left = max(self.__xmin, left - d)
new_right = new_left + d
self.__animate(left, new_left - left, right, new_right - right)
self.__animate(left, new_left, right, new_left + d)

def __on_right(self, event):
left, right = self._get_xlim()
d = right - left
new_right = min(self.__xmax, right + d)
new_left = new_right - d
self.__animate(left, new_left - left, right, new_right - right)
self.__animate(left, new_right - d, right, new_right)

def _set_xlim(self, left, right):
for ax in self.__axes:
Expand Down
2 changes: 1 addition & 1 deletion eelbrain/plot/_utsnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def __init__(self, epochs, Xax=None, xlabel=True, ylabel=True,
e0 = epochs[0][0]
self._configure_xaxis_dim(e0.get_dim(xdim), xlabel, xticklabels)
self._configure_yaxis_dim(e0.get_dim(ydim), ylabel, scalar=False)
XAxisMixin.__init__(self, epochs, xdim, xlim)
XAxisMixin.__init__(self, epochs, xdim, xlim, im=True)
self._show()

def _fill_toolbar(self, tb):
Expand Down

0 comments on commit a855c49

Please sign in to comment.