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

aewallin / allantools / 8946273051

04 May 2024 12:01AM UTC coverage: 89.337% (-2.8%) from 92.13%
8946273051

Pull #158

github

web-flow
Merge f8ba163ff into 8faefa93f
Pull Request #158: fix usage of matplotlib.Axes.grid (fixes #128)

2 of 4 new or added lines in 1 file covered. (50.0%)

68 existing lines in 7 files now uncovered.

2723 of 3048 relevant lines covered (89.34%)

1.78 hits per line

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

75.86
/allantools/plot.py
1
"""
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
1✔
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):
2✔
51
        """ set ``no_display`` to ``True`` when we don't have an X-window
52
        (e.g. for tests)
53
        """
54
        try:
2✔
55
            import matplotlib
2✔
56
            if no_display:
2✔
57
                matplotlib.use('Agg')
2✔
58
            import matplotlib.pyplot as plt
2✔
59
            self.plt = plt
2✔
60
        except ImportError:
×
61
            raise RuntimeError("Matplotlib is required for plotting")
×
62
        self.fig, self.ax = plt.subplots()
2✔
63
        self.ax.set_xscale("log")
2✔
64
        self.ax.set_yscale("log")
2✔
65

66
    def plot(self, atDataset,
2✔
67
             errorbars=False,
68
             grid=False,
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:
2✔
86
            self.ax.errorbar(atDataset.out["taus"],
2✔
87
                             atDataset.out["stat"],
88
                             yerr=atDataset.out["stat_err"],
89
                             **kwargs)
90
        else:
91
            self.ax.plot(atDataset.out["taus"],
×
92
                         atDataset.out["stat"],
93
                         **kwargs)
94
        self.ax.set_xlabel("Tau")
2✔
95
        self.ax.set_ylabel(atDataset.out["stat_id"])
2✔
96

97
        if grid:
2✔
NEW
98
            self.ax.grid(True, which="minor", ls="-", color='0.65')
×
NEW
99
            self.ax.grid(True, which="major", ls="-", color='0.25')
×
100
        else:
101
            self.ax.grid(False)
2✔
102

103
    def show(self):
2✔
104
        """Calls matplotlib.pyplot.show()
105

106
        Keeping this separated from ``plot()`` allows to tweak display before
107
        rendering
108
        """
109
        self.plt.show()
×
110

111
    def save(self, f):
2✔
112
        """Save figure to file
113
        """
114
        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

© 2026 Coveralls, Inc