'calculate the offset transform performed by the spine'

def _calc_offset_transform(self):

    self._ensure_position_is_set()
    position = self._position
    if isinstance(position, six.string_types):
        if (position == u'center'):
            position = (u'axes', 0.5)
        elif (position == u'zero'):
            position = (u'data', 0)
    assert (len(position) == 2), u'position    should    be    2-tuple'
    (position_type, amount) = position
    assert (position_type in (u'axes', u'outward', u'data'))
    if (position_type == u'outward'):
        if (amount == 0):
            self._spine_transform = (u'identity', mtransforms.IdentityTransform())
        elif (self.spine_type in [u'left', u'right', u'top', u'bottom']):
            offset_vec = {u'left': ((-1), 0), u'right': (1, 0), u'bottom': (0, (-1)), u'top': (0, 1)}[self.spine_type]
            offset_x = ((amount * offset_vec[0]) / 72.0)
            offset_y = ((amount * offset_vec[1]) / 72.0)
            self._spine_transform = (u'post', mtransforms.ScaledTranslation(offset_x, offset_y, self.figure.dpi_scale_trans))
        else:
            warnings.warn((u'unknown    spine    type    "%s":    no    spine    offset    performed' % self.spine_type))
            self._spine_transform = (u'identity', mtransforms.IdentityTransform())
    elif (position_type == u'axes'):
        if (self.spine_type in (u'left', u'right')):
            self._spine_transform = (u'pre', mtransforms.Affine2D.from_values(0, 0, 0, 1, amount, 0))
        elif (self.spine_type in (u'bottom', u'top')):
            self._spine_transform = (u'pre', mtransforms.Affine2D.from_values(1, 0, 0, 0, 0, amount))
        else:
            warnings.warn((u'unknown    spine    type    "%s":    no    spine    offset    performed' % self.spine_type))
            self._spine_transform = (u'identity', mtransforms.IdentityTransform())
    elif (position_type == u'data'):
        if (self.spine_type in (u'right', u'top')):
            amount -= 1
        if (self.spine_type in (u'left', u'right')):
            self._spine_transform = (u'data', mtransforms.Affine2D().translate(amount, 0))
        elif (self.spine_type in (u'bottom', u'top')):
            self._spine_transform = (u'data', mtransforms.Affine2D().translate(0, amount))
        else:
            warnings.warn((u'unknown    spine    type    "%s":    no    spine    offset    performed' % self.spine_type))
            self._spine_transform = (u'identity', mtransforms.IdentityTransform())
