Пример #1
0
def pixels_to_figcoords(
        length_pixels: float,
        trans: Transform,
        direction: str = "both") -> Union[float, Tuple[float, float]]:
    """
    Convert a length in display coordinates to a length in data or axes
    coordinates.
    
    :param length_pixels:  A absolute size, in display coordinates (i.e.
                pixels).
    :param trans:  Coordinate system to transform to. Examples: `ax.transAxes`,
                `ax.transData`, `ax.get_xaxis_transform()`, and
                `ax.get_yaxis_transform()`.
    :param direction:  Which dimension to return. 'h' for horizontal (x), 'v' for
                vertical (y), or 'both' for both.
    :return:  Length in `trans` coordinates. A tuple when orient="both". A
                scalar otherwise.
    """
    # Get the origin in display coordinates (i.e. pixels):
    origin = trans.transform([0, 0])
    # Transform display coordinates to data or axes coordinates:
    x, y = trans.inverted().transform(origin + length_pixels)
    if direction == "h":
        return x
    elif direction == "v":
        return y
    elif direction == "both":
        return x, y
Пример #2
0
 def transform(self, lat):
     try:
         return Transform.transform(self, lat)
     except NotImplementedError:
         return self.transform_non_affine(lat)