# Buggy code
def _get_step(self, axis):
    # TODO: need to check if this is working fine, particularly with
    """Use to determine the size of the widget with support for non
    uniform axis.
    """
    return axis.index2value(axis.index + 1) - axis.index2value(axis.index)


# Traceback (IndexError)
mod.plot()
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-6-97bc6e2748ea> in <module>
----> 1 mod.plot()

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\models\model1d.py in plot(self, plot_components, **kwargs)
658
659         # If new coordinates are assigned
--> 660         self.signal.plot(**kwargs)
661         _plot = self.signal._plot
662         l1 = _plot.signal_plot.ax_lines[0]

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\signal.py in plot(self, navigator, axes_manager, plot_markers, **kwargs)
2159                     " \"slider\", None, a Signal instance")
2160
-> 2161         self._plot.plot(**kwargs)
2162         self.events.data_changed.connect(self.update_plot, [])
2163         if self._plot.signal_plot:

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\mpl_he.py in plot(self, **kwargs)
174             pointer = self.assign_pointer()
175             if pointer is not None:
--> 176                 self.pointer = pointer(self.axes_manager)
177                 self.pointer.color = 'red'
178                 self.pointer.connect_navigate()

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\_widgets\rectangles.py in __init__(self, axes_manager, **kwargs)
39
40     def __init__(self, axes_manager, **kwargs):
---> 41         super(SquareWidget, self).__init__(axes_manager, **kwargs)
42
43     def _set_patch(self):

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in __init__(self, axes_manager, **kwargs)
768
769     def __init__(self, axes_manager, **kwargs):
--> 770         super(Widget2DBase, self).__init__(axes_manager, **kwargs)
771         self.border_thickness = 2
772

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in __init__(self, axes_manager, **kwargs)
546     def __init__(self, axes_manager, **kwargs):
547         super(ResizableDraggableWidgetBase, self).__init__(
--> 548             axes_manager, **kwargs)
549         if not self.axes:
550             self._size = np.array([1])

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in __init__(self, axes_manager, **kwargs)
337         if self.axes_manager is not None:
338             if self.axes_manager.navigation_dimension > 0:
--> 339                 self.axes = self.axes_manager.navigation_axes[0:1]
340             else:
341                 self.axes = self.axes_manager.signal_axes[0:1]

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in <lambda>(s, v)
97
98     axes = property(lambda s: s._get_axes(),
---> 99                     lambda s, v: s._set_axes(v))
100
101     def is_on(self):

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in _set_axes(self, axes)
570         super(ResizableDraggableWidgetBase, self)._set_axes(axes)
571         if self.axes:
--> 572             self._size = np.array([self._get_step(ax) for ax in self.axes])
573
574     def _get_step(self, axis):

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in <listcomp>(.0)
570         super(ResizableDraggableWidgetBase, self)._set_axes(axes)
571         if self.axes:
--> 572             self._size = np.array([self._get_step(ax) for ax in self.axes])
573
574     def _get_step(self, axis):

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\drawing\widget.py in _get_step(self, axis)
577         uniform axis.
578         """
--> 579         return axis.index2value(axis.index + 1) - axis.index2value(axis.index)
580
581     def _get_size(self):

c:\users\nicolastappy\documents\git\hyperspy\hyperspy\axes.py in index2value(self, index)
503             return self.axis[index.ravel()].reshape(index.shape)
504         else:
--> 505             return self.axis[index]
506
507     def value2index(self, value, rounding=round):

IndexError: index 4 is out of bounds for axis 0 with size 4

# Fixed code
def _get_step(self, axis):
    # TODO: need to check if this is working fine, particularly with
    """Use to determine the size of the widget with support for non
    uniform axis.
    """
    if axis.index >= axis.size - 1:
        return axis.index2value(axis.index) - axis.index2value(axis.index - 1)
    else:
        return axis.index2value(axis.index + 1) - axis.index2value(axis.index)