コード例 #1
0
ファイル: panel.py プロジェクト: zzpwahaha/ehtplot
    def __call__(self, ax, **kwargs):
        """Panel realizer

        Realize a panel to a generator of matplotlib subaxeses by
        combining the saved and new arguments.  It accepts the same
        keyworded arguments as Visual.__init__().  Therefore, its
        argument list matches Visual.__init__() with `panelable`
        replaced by `ax`.

        Args:
            ax (matplotlib.axis.Axes): A matplotlib Axes for Panel's
                subaxeses to realize on.
            **kwargs (dict): Arbitrary Panel-specific keyworded
                arguments that are used to construct the subaxeses.

        """
        kwprops = merge_dict(self.kwprops, kwargs)

        box = divide(ax.get_position(),
                     list(map(type, self.panels)).count(Panel),
                     inrow=kwprops['inrow'])

        for p in self.panels:
            if isinstance(p, Panel):
                subax = newaxes(ax.figure, next(box))
                yield subax
            else:
                ax.axis('on')
                yield ax
コード例 #2
0
ファイル: panel.py プロジェクト: zzpwahaha/ehtplot
    def draw(self, ax, *args, **kwargs):
        """Panel drawer/renderer

        Draw or render a Panel by combining the saved and new
        arguments.  Its argument list is designed to match
        Visual.draw() so that a Panel and Visual draw in the same way.
        This duck typing allows Panel to draw all its subpanels and
        subvisuals recusively.  Saved and new panel properties are
        combined to create subaxeses.  The passed `args` and
        non-Panel-specific keyworded arguments are passed recusively
        to the subpanels and eventially to some ehtplot Visuals.

        Args:
            ax (matplotlib.axis.Axes): A matplotlib Axes for Panel to
                draw/render on.
            *args (tuple): Variable length argument list that is
                eventually passed to some ehtplot Visuals.
            **kwargs (dict): Arbitrary keyworded arguments that are
                split into Panel-specific and non-Panel-specific
                keyworded arguments.  The Panel-specific ones are used
                to construct the subaxeses, while others are
                eventually passed to some ehtplot Visuals.

        """
        kwargs, kwprops = split_dict(kwargs, self._prop_keys)
        kwprops = merge_dict(self.kwprops, kwprops)
        return [
            p.draw(a, *args, **kwargs)
            for p, a in zip(self.panels, self(ax, **kwprops))
        ]
コード例 #3
0
ファイル: figure.py プロジェクト: zzpwahaha/ehtplot
    def __call__(self, **kwargs):
        """Figure realizer

        The Figure class only keeps track of a root panel.  It does
        not contain an actual matplotlib Figure instance.  Whenever a
        figure needs to be created, Figure creates a new matplotlib
        Figure in order to drew/rendered/realized the figure.

        Args:

            **kwargs (dict): Arbitrary Figure-specific keyworded
                arguments that are used to construct the matplotlib
                Figure.

        """
        kwprops = merge_dict(self.kwprops, kwargs)
        style = kwprops.pop('style')

        with mpl.rc_context():
            mpl.rcdefaults()
            plt.style.use(style)

            imode = mpl.is_interactive()
            if imode:
                plt.ioff()

            fig = plt.figure(**kwprops)
            ax = newaxes(fig)
            yield fig, ax

            if imode:
                plt.ion()
コード例 #4
0
    def __call__(self, ax, *args, **kwargs):
        """Visual realizer

        Realize a visual by combining the saved and new arguments.
        The realization uses the new `args` list if it is provided,
        and uses the saved attribute otherwise.  Saved and new
        `kwargs` are always combined.

        Args:
            ax (matplotlib.axis.Axes): A matplotlib Axes for Visual to
                draw/render/realize on.
            *args (tuple): Variable length argument list that
                overrides the saved on when realizing an instance of
                Visual.
            **kwargs (dict): Arbitrary keyworded arguments that are
                passed to the visualizing function the when realizing
                an instance of Visual.

        """
        props = args if args else self.props
        kwprops = merge_dict(self.kwprops, kwargs)
        return self.visual(ax, *props, **kwprops)
コード例 #5
0
ファイル: figure.py プロジェクト: zzpwahaha/ehtplot
    def draw(self, *args, **kwargs):
        """Figure drawer/renderer

        The Figure class only keeps track of a root panel.  It does
        not contain an actual matplotlib Figure instance.  Whenever a
        figure needs to be created, Figure creates a new matplotlib
        Figure in order to drew/rendered/realized the figure.

        Args:
            *args (tuple): Variable length argument list that is
                passed to the root panel.
            **kwargs (dict): Arbitrary keyworded arguments that are
                split into properties of the figure and the panel.

        """
        kwargs, kwprops = split_dict(kwargs, self._prop_keys)
        kwprops = merge_dict(self.kwprops, kwprops)

        with self(**kwprops) as (fig, ax):
            self.panel.draw(ax, *args, **kwargs)

        return fig
コード例 #6
0
ファイル: panel.py プロジェクト: zzpwahaha/ehtplot
    def __init__(self, panelable, **kwargs):
        """Panel initializer

        The Panel class is the "node class" that allows ehtplot to
        hierarchically organize subpanels and subvisuals, and to
        manage their properties.

        Args:
            panelable (list): A list that contains subpanels and/or
                subvisuals.
            **kwargs (dict): Arbitrary keyworded arguments that are
                passed to the subaxes constructor when realizing an
                instance of Panel.

        Attributes:
            panels (list): A list of subpanels, subvisuals, or list of
                them generated from the `args` argument.
            kwprops (dict): The default keywords used in creating
                subaxeses when realizing an instance of Panel.

        """
        self.panels = panelable
        self.kwprops = merge_dict(self._default_kwprops, kwargs)
コード例 #7
0
ファイル: figure.py プロジェクト: zzpwahaha/ehtplot
    def __init__(self, panel, **kwargs):
        """Figure initializer

        The Figure class takes a single argument with type Panel:

            fig = Figure(pnl, kw0=..., kw1=..., ...)

        this makes `pnl` the built-in root panel of `fig`.

        Args:
            panel (ehtplot.Panel): The root panel of the Figure.
            **kwargs (dict): If Figure is initialized in the second
                way, then this is an arbitrary keyworded arguments
                passed to create the root panel.

        Attributes:
            panel (ehtplot.Panel): The root panel of the Figure.
            kwprops (dict): The default keywords for creating a
                figure.

        """
        self.panel = panel
        self.kwprops = merge_dict(self._default_kwprops, kwargs)