Example #1
0
    def __init__(self, **kwargs):

        super(ScatterViewerState, self).__init__()

        self.limits_cache = {}

        self.x_lim_helper = StateAttributeLimitsHelper(
            self,
            attribute='x_att',
            lower='x_min',
            upper='x_max',
            log='x_log',
            margin=0.04,
            limits_cache=self.limits_cache)

        self.y_lim_helper = StateAttributeLimitsHelper(
            self,
            attribute='y_att',
            lower='y_min',
            upper='y_max',
            log='y_log',
            margin=0.04,
            limits_cache=self.limits_cache)

        self.add_callback('layers', self._layers_changed)

        self.x_att_helper = ComponentIDComboHelper(self,
                                                   'x_att',
                                                   pixel_coord=True,
                                                   world_coord=True)
        self.y_att_helper = ComponentIDComboHelper(self,
                                                   'y_att',
                                                   pixel_coord=True,
                                                   world_coord=True)

        self.plot_mode_helper = ComboHelper(self, 'plot_mode')
        self.plot_mode_helper.choices = [
            proj for proj in get_projection_names()
            if proj not in ['3d', 'scatter_density']
        ]
        self.plot_mode_helper.selection = 'rectilinear'

        self.angle_unit_helper = ComboHelper(self, 'angle_unit')
        self.angle_unit_helper.choices = ['radians', 'degrees']
        self.angle_unit_helper.selection = 'radians'

        self.update_from_dict(kwargs)

        self.add_callback('x_log', self._reset_x_limits)
        self.add_callback('y_log', self._reset_y_limits)

        if self.using_polar:
            self.full_circle()
Example #2
0
def get_mpl_transform(mpl_proj):
    r"""This returns an instantiated transform function given a transform
    function name and arguments.

    Parameters
    ----------
    mpl_proj : string or tuple
        the matplotlib projection type. Can take the form of string or tuple.

    Examples
    --------

    >>> get_mpl_transform("PlateCarree")

    >>> get_mpl_transform(('RotatedPole', (), {'pole_latitude':37.5,
    ...                    'pole_longitude':177.5}))

    """
    # first check to see if the tranform dict is empty, if it is fill it with
    # the cartopy functions
    if not valid_transforms:
        for mpl_transform in transform_list:
            valid_transforms[mpl_transform] = cartopy_importer(mpl_transform)

    # check to see if mpl_proj is a string or tuple, and construct args and
    # kwargs to pass to cartopy function based on that.
    key = None
    if isinstance(mpl_proj, str):
        key = mpl_proj
        args = ()
        kwargs = {}
        instantiated_func = valid_transforms[key](*args, **kwargs)
    elif isinstance(mpl_proj, tuple):
        if len(mpl_proj) == 2:
            key, args = mpl_proj
            kwargs = {}
        elif len(mpl_proj) == 3:
            key, args, kwargs = mpl_proj
        instantiated_func = valid_transforms[key](*args, **kwargs)
    elif hasattr(mpl_proj, "globe"):
        # cartopy transforms have a globe method associated with them
        key = mpl_proj
        instantiated_func = mpl_proj
    elif hasattr(mpl_proj, "set_transform"):
        # mpl axes objects have a set_transform method, so we'll check if that
        # exists on something passed in.
        key = mpl_proj
        instantiated_func = mpl_proj
    elif hasattr(mpl_proj, "name"):
        # last we'll check if the transform is in the list of registered
        # projections in matplotlib.
        from matplotlib.projections import get_projection_names

        registered_projections = get_projection_names()
        if mpl_proj.name in registered_projections:
            key = mpl_proj
            instantiated_func = mpl_proj
        else:
            key = None

    # build in a check that if none of the above options are satisfied by what
    # the user passes that None is returned for the instantiated function
    if key is None:
        instantiated_func = None
    return instantiated_func
Example #3
0
from matplotlib.image import FigureImage

import matplotlib.colorbar as cbar

from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
from matplotlib.legend import Legend
from matplotlib.patches import Rectangle
from matplotlib.projections import (get_projection_names,
                                    process_projection_requirements)
from matplotlib.text import Text, _process_text_args
from matplotlib.transforms import (Affine2D, Bbox, BboxTransformTo,
                                    TransformedBbox)


docstring.interpd.update(projection_names = get_projection_names())

class AxesStack(Stack):
    """
    Specialization of the Stack to handle all tracking of Axes in a Figure.
    This stack stores ``key, (ind, axes)`` pairs, where:

        * **key** should be a hash of the args and kwargs
          used in generating the Axes.
        * **ind** is a serial number for tracking the order
          in which axes were added.

    The AxesStack is a callable, where ``ax_stack()`` returns
    the current axes. Alternatively the :meth:`current_key_axes` will
    return the current key and associated axes.