'Return a scale factor for converting from units to pixels'

def _dots_per_unit(self, units):

    ax = self.ax
    if (units in (u'x', u'y', u'xy')):
        if (units == u'x'):
            dx0 = ax.viewLim.width
            dx1 = ax.bbox.width
        elif (units == u'y'):
            dx0 = ax.viewLim.height
            dx1 = ax.bbox.height
        else:
            dxx0 = ax.viewLim.width
            dxx1 = ax.bbox.width
            dyy0 = ax.viewLim.height
            dyy1 = ax.bbox.height
            dx1 = np.hypot(dxx1, dyy1)
            dx0 = np.hypot(dxx0, dyy0)
        dx = (dx1 / dx0)
    elif (units == u'width'):
        dx = ax.bbox.width
    elif (units == u'height'):
        dx = ax.bbox.height
    elif (units == u'dots'):
        dx = 1.0
    elif (units == u'inches'):
        dx = ax.figure.dpi
    else:
        raise ValueError(u'unrecognized    units')
    return dx
