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

aewallin / allantools / 6997134815

26 Nov 2023 05:57PM UTC coverage: 74.663% (-10.1%) from 84.742%
6997134815

push

github

aewallin
coverage workflow

1273 of 1705 relevant lines covered (74.66%)

2.17 hits per line

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

52.17
/allantools/plot.py
1
"""
2
Allantools plotting utilities
3

4
**Authors:** Frederic Meynadier (frederic.meynadier "at" gmail.com),
5
    Mike DePalatis (http://mike.depalatis.net)
6

7
Version history
8
---------------
9

10
**2019.07**
11
- Initial release
12

13
License
14
-------
15

16
This program is free software: you can redistribute it and/or modify
17
it under the terms of the GNU Lesser General Public License as published by
18
the Free Software Foundation, either version 3 of the License, or
19
(at your option) any later version.
20

21
This program is distributed in the hope that it will be useful,
22
but WITHOUT ANY WARRANTY; without even the implied warranty of
23
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
GNU Lesser General Public License for more details.
25

26
You should have received a copy of the GNU Lesser General Public License
27
along with this program.  If not, see <http://www.gnu.org/licenses/>.
28

29
"""
30

31

32
class Plot(object):
2✔
33
    """ A class for plotting data once computed by Allantools
34

35
    :Example:
36
        ::
37

38
            import allantools
39
            import numpy as np
40
            a = allantools.Dataset(data=np.random.rand(1000))
41
            a.compute("mdev")
42
            b = allantools.Plot()
43
            b.plot(a)
44
            b.show()
45

46
    Uses matplotlib. self.fig and self.ax stores the return values of
47
    matplotlib.pyplot.subplots(). plot() sets various defaults, but you
48
    can change them by using standard matplotlib method on self.fig and self.ax
49
    """
50
    def __init__(self, no_display=False):
3✔
51
        """ set ``no_display`` to ``True`` when we don't have an X-window
52
        (e.g. for tests)
53
        """
54
        try:
3✔
55
            import matplotlib
3✔
56
            if no_display:
3✔
57
                matplotlib.use('Agg')
3✔
58
            import matplotlib.pyplot as plt
3✔
59
            self.plt = plt
3✔
60
        except ImportError:
×
61
            raise RuntimeError("Matplotlib is required for plotting")
×
62
        self.fig, self.ax = plt.subplots()
3✔
63
        self.ax.set_xscale("log")
3✔
64
        self.ax.set_yscale("log")
3✔
65

66
    def plot(self, atDataset,
2✔
67
             errorbars=False,
×
68
             grid=False,
1✔
69
             **kwargs):
×
70
        """ Use matplotlib methods for plotting
×
71

72
        Additional keywords arguments are passed to
×
73
        :py:func:`matplotlib.pyplot.plot`.
×
74

75
        Parameters
×
76
        ----------
×
77
        atDataset : allantools.Dataset()
×
78
            a dataset with computed data
×
79
        errorbars : boolean
×
80
            Plot errorbars. Defaults to False
×
81
        grid : boolean
×
82
            Plot grid. Defaults to False
×
83

84
        """
×
85
        if errorbars:
3✔
86
            self.ax.errorbar(atDataset.out["taus"],
3✔
87
                             atDataset.out["stat"],
3✔
88
                             yerr=atDataset.out["stat_err"],
3✔
89
                             **kwargs)
3✔
90
        else:
×
91
            self.ax.plot(atDataset.out["taus"],
×
92
                         atDataset.out["stat"],
×
93
                         **kwargs)
×
94
        self.ax.set_xlabel("Tau")
3✔
95
        self.ax.set_ylabel(atDataset.out["stat_id"])
3✔
96
        self.ax.grid(grid, which="minor", ls="-", color='0.65')
3✔
97
        self.ax.grid(grid, which="major", ls="-", color='0.25')
3✔
98

99
    def show(self):
3✔
100
        """Calls matplotlib.pyplot.show()
101

102
        Keeping this separated from ``plot()`` allows to tweak display before
103
        rendering
104
        """
105
        self.plt.show()
×
106

107
    def save(self, f):
3✔
108
        """Save figure to file
109
        """
110
        self.plt.savefig(f)
×
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

© 2025 Coveralls, Inc