• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

morganjwilliams / pyrolite / 11850314246

15 Nov 2024 03:42AM UTC coverage: 90.077% (-0.3%) from 90.339%
11850314246

push

github

morganjwilliams
Update example for interactive plotting API

0 of 30 new or added lines in 2 files covered. (0.0%)

9 existing lines in 8 files now uncovered.

6236 of 6923 relevant lines covered (90.08%)

8.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pyrolite/util/plot/backend.py
1
import warnings
×
2

3
import pandas as pd
×
4

5
from ..log import Handle
×
6
from ...plot import pyroplot_matplotlib
×
7

8
logger = Handle(__name__)
×
9

10
BACKEND = "matplotlib"
×
11

12

NEW
13
def _get_backend():
×
NEW
14
    return BACKEND
×
15

16

17
_backend_accessors = {"matplotlib": pyroplot_matplotlib}
×
18
try:
×
19
    import plotly.graph_objects as go
×
20

21
    HAVE_PLOTLY = True
×
22

23
    from .plotly import pyroplot_plotly
×
24

25
    _backend_accessors["plotly"] = pyroplot_plotly
×
26

27
except ImportError:
×
28
    HAVE_PLOTLY = False
×
29

30

31
def set_plotting_backend(backend=None, revert=False):
×
32
    if backend is not None:
×
33
        if backend in ["matplotlib", "plotly"]:
×
34
            global BACKEND
NEW
35
            if BACKEND != backend:
×
NEW
36
                logger.debug(
×
37
                    "{} plotting backend to {}".format(
38
                        "Reverting" if revert else "Setting", backend
39
                    )
40
                )
NEW
41
                BACKEND = backend
×
42
        else:
43
            raise NotImplementedError("Backend {} not available.")
×
44

45

NEW
46
class pyroplot(object):
×
NEW
47
    def __init__(self, obj):
×
48
        """
49
        Custom dataframe accessor for pyrolite plotting.
50

51
        Notes
52
        -----
53
            This accessor enables the coexistence of array-based plotting functions and
54
            methods for pandas objects. This enables some separation of concerns.
55
        """
NEW
56
        self._obj = obj
×
57

NEW
58
    def scatter(self, *args, backend=None, **kwargs):
×
NEW
59
        with Backend(backend=backend):
×
NEW
60
            return _backend_accessors[_get_backend()](self._obj).scatter(
×
61
                *args, **kwargs
62
            )
63

NEW
64
    def spider(self, *args, backend=None, **kwargs):
×
NEW
65
        with Backend(backend=backend):
×
NEW
66
            return _backend_accessors[_get_backend()](self._obj).spider(*args, **kwargs)
×
67

68

NEW
69
with warnings.catch_warnings():
×
70
    # can get invalid values which raise RuntimeWarnings
71
    # consider changing to np.errstate
NEW
72
    warnings.simplefilter("ignore", category=UserWarning)
×
NEW
73
    pd.api.extensions.register_dataframe_accessor("pyroplot")(
×
74
        pyroplot  # _backend_accessors.get(self.backend)
75
    )
76

77

UNCOV
78
class Backend:
×
79
    """
80
    Backend context manager for pyrolite plotting.
81
    """
82

83
    def __init__(self, backend=None):
×
NEW
84
        self.start = _get_backend()
×
85
        self.backend = backend
×
86
        set_plotting_backend(self.backend)
×
87

UNCOV
88
    def __enter__(self):
×
89
        return self
×
90

91
    def __exit__(self, exc_type, exc_value, exc_traceback):
×
92
        # only reset when changed in the first place?
93
        if self.backend is not None:
×
94
            set_plotting_backend(self.start, revert=True)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc