How to use the psyplot.project.Project function in psyplot

To help you get started, we’ve selected a few psyplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Chilipp / psyplot / tests / test_project.py View on Github external
def test_save_and_load_06_post_fmt(self):
        """Test whether the :attr:`psyplot.plotter.Plotter.post` fmt works"""
        psy.register_plotter('test_plotter', import_plotter=True,
                             module='test_plotter', plotter_name='TestPlotter')
        ds = psy.open_dataset(bt.get_file('test-t2m-u-v.nc'))
        plt.close('all')
        sp = psy.plot.test_plotter(ds, name=['t2m', 'u'], x=0, y=4,
                                   ax=(2, 2, 1), fmt1='test',
                                   post='self.ax.set_title("test")')
        self.assertEqual(sp.plotters[0].ax.get_title(), 'test')
        fname = 'test.pkl'
        self._created_files.add(fname)
        sp.save_project(fname)
        psy.close('all')
        # test without enabled post
        sp = psy.Project.load_project(fname)
        self.assertEqual(sp.plotters[0].ax.get_title(), '')
        psy.close('all')
        # test with enabled post
        sp = psy.Project.load_project(fname, enable_post=True)
        self.assertEqual(sp.plotters[0].ax.get_title(), 'test')
github ARVE-Research / gwgen / gwgen / main.py View on Github external
d['project_file'] = project_output
        d['nc_file'] = nc_output

        if what == 'slope':
            ylabel = 'Simulated/Observed'
            if vname == 'wind':
                ylabel = '$\\sqrt{{' + ylabel + '}}$'
        else:
            ylabel = 'Simulated - Observed'
        diff_symbol = ylabel
        if vname == 'tmin':
            ylabel += ' [$^\circ$C]'

        # --- slope bias correction
        if osp.exists(project_output) and not new_project:
            mp = psy.Project.load_project(project_output, datasets=[ds])
            sp2 = mp.linreg
        else:
            import seaborn as sns
            sns.set_style('white')
            sp1 = psy.plot.lineplot(ds, name=what, coord='unorm',
                                    linewidth=0, marker='o', legend=False)
            label = '$%s = %s$' % (diff_symbol, ' '.join(
                '%(c{})+4.3f{}'.format(i, get_symbol(i))
                for i in range(deg + 1)))
            sp2 = psy.plot.linreg(
                 ds, name=what, ax=sp1[0].ax,
                 coord='unorm', fit='poly' + str(int(deg)),
                 ylabel=ylabel,
                 legendlabels=label,
                 legend={'fontsize': 'large', 'loc': 'upper left'},
                 xlabel='Random number from normal distribution')
github Chilipp / psyplot / psyplot / project.py View on Github external
Unregister a :class:`psyplot.plotter.Plotter` for the projects

    Parameters
    ----------
    identifier: str
        Name of the attribute that is used to filter for the instances
        belonging to this plotter or to create plots with this plotter
    sorter: bool
        If True, the identifier will be unregistered from the :class:`Project`
        class
    plot_func: bool
        If True, the identifier will be unregistered from the
        :class:`ProjectPlotter` class
    """
    d = registered_plotters.get(identifier, {})
    if sorter and hasattr(Project, identifier):
        delattr(Project, identifier)
        d['sorter'] = False
    if plot_func and hasattr(ProjectPlotter, identifier):
        for cls in [ProjectPlotter, DatasetPlotter, DataArrayPlotter]:
            delattr(cls, identifier)
        try:
            delattr(plot, '_' + identifier)
        except AttributeError:
            pass
        d['plot_func'] = False
    if sorter and plot_func:
        registered_plotters.pop(identifier, None)
github Chilipp / psyplot / psyplot / project.py View on Github external
registered_plotters = {}

for _identifier, _plotter_settings in rcParams['project.plotters'].items():
    register_plotter(_identifier, **_plotter_settings)


def get_project_nums():
    """Returns the project numbers of the open projects"""
    return [p.num for p in _open_projects]

#: :class:`ProjectPlotter` of the current project. See the class documentation
#: for available plotting methods
plot = ProjectPlotter()

#: The project class that is used for creating new projects
PROJECT_CLS = Project

psyplot._project_imported = True
github Chilipp / psyplot / psyplot / project.py View on Github external
%(ProjectPlotter._register_plotter.other_parameters)s
    """
    if plotter_cls is None:
        if ((import_plotter is None and rcParams['project.auto_import']) or
                import_plotter):
            try:
                plotter_cls = getattr(import_module(module), plotter_name)
            except Exception as e:
                critical(("Could not import %s!\n" % module) +
                         e.message if six.PY2 else str(e))
                return
    if sorter:
        if hasattr(Project, identifier):
            raise ValueError(
                "Project class already has a %s attribute" % identifier)
        Project._register_plotter(
            identifier, module, plotter_name, plotter_cls)
    if plot_func:
        if hasattr(ProjectPlotter, identifier):
            raise ValueError(
                "Project class already has a %s attribute" % identifier)
        ProjectPlotter._register_plotter(
            identifier, module, plotter_name, plotter_cls, **kwargs)
        DatasetPlotter._register_plotter(
            identifier, module, plotter_name, plotter_cls, **kwargs)
        DataArrayPlotter._register_plotter(
            identifier, module, plotter_name, plotter_cls, **kwargs)
    if identifier not in registered_plotters:
        kwargs.update(dict(
            module=module, plotter_name=plotter_name, sorter=sorter,
            plot_func=plot_func, import_plotter=import_plotter))
        registered_plotters[identifier] = kwargs
github Chilipp / psyplot / psyplot / project.py View on Github external
be ``None`` or a list of the types specified for `base`
        %(Plotter.share.parameters.no_keys|plotters)s

        See Also
        --------
        psyplot.plotter.share"""
        if by is not None:
            if base is not None:
                if hasattr(base, 'psy') or isinstance(base, Plotter):
                    base = [base]
                if by.lower() in ['ax', 'axes']:
                    bases = {ax: p[0] for ax, p in six.iteritems(
                        Project(base).axes)}
                elif by.lower() in ['fig', 'figure']:
                    bases = {fig: p[0] for fig, p in six.iteritems(
                        Project(base).figs)}
                else:
                    raise ValueError(
                        "*by* must be out of {'fig', 'figure', 'ax', 'axes'}. "
                        "Not %s" % (by, ))
            else:
                bases = {}
            projects = self.axes if by == 'axes' else self.figs
            for obj, p in projects.items():
                p.share(bases.get(obj), keys, **kwargs)
        else:
            plotters = self.plotters
            if not plotters:
                return
            if base is None:
                if len(plotters) == 1:
                    return
github Chilipp / psyplot / psyplot / project.py View on Github external
by: {'fig', 'figure', 'ax', 'axes'}
            Share the formatoptions only with the others on the same
            ``'figure'`` or the same ``'axes'``. In this case, base must either
            be ``None`` or a list of the types specified for `base`
        %(Plotter.share.parameters.no_keys|plotters)s

        See Also
        --------
        psyplot.plotter.share"""
        if by is not None:
            if base is not None:
                if hasattr(base, 'psy') or isinstance(base, Plotter):
                    base = [base]
                if by.lower() in ['ax', 'axes']:
                    bases = {ax: p[0] for ax, p in six.iteritems(
                        Project(base).axes)}
                elif by.lower() in ['fig', 'figure']:
                    bases = {fig: p[0] for fig, p in six.iteritems(
                        Project(base).figs)}
                else:
                    raise ValueError(
                        "*by* must be out of {'fig', 'figure', 'ax', 'axes'}. "
                        "Not %s" % (by, ))
            else:
                bases = {}
            projects = self.axes if by == 'axes' else self.figs
            for obj, p in projects.items():
                p.share(bases.get(obj), keys, **kwargs)
        else:
            plotters = self.plotters
            if not plotters:
                return
github Chilipp / psyplot / psyplot / project.py View on Github external
def _scp(p, main=False):
    """scp version that allows a bit more control over whether the project is a
    main project or not"""
    global _current_subproject
    global _current_project
    if p is None:
        mp = project() if main or _current_project is None else \
            _current_project
        _current_subproject = Project(main=mp)
    elif not main:
        _current_subproject = p
    else:
        _current_project = p