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

ac-i2i-engineering / MatPlus / 13486272155

23 Feb 2025 07:37PM UTC coverage: 92.308% (+4.6%) from 87.727%
13486272155

Pull #9

github

BestLocation
add coverage
Pull Request #9: Added boxplot and tests

115 of 116 new or added lines in 2 files covered. (99.14%)

348 of 377 relevant lines covered (92.31%)

7.77 hits per line

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

97.56
/MatPlus/BoxPlot.py
1
import matplotlib.pyplot as plt
6✔
2
import numpy as np
6✔
3

4

5
class BoxPlot:
6✔
6
    def __init__(self, data, notch=False, sym="b", vert=True, whis=1.5):
6✔
7
        """Initializes Boxplot object with the following parameters:
8
        data: data to be plotted
9
        notch: notch shape of the box
10
        sym: symbol for outliers
11
        vert: vertical orientation (deprecated, use orientation instead)
12
        whis: whisker length in number of IQR
13
        """
14
        # Validate data type
15
        if not isinstance(data, (list, np.ndarray)):
6✔
NEW
16
            raise TypeError("Data must be a list or numpy array")
×
17

18
        # Validate numeric data
19
        try:
6✔
20
            numeric_data = [float(x) for x in data]
6✔
21
        except (ValueError, TypeError):
6✔
22
            raise TypeError("All elements must be numeric")
6✔
23

24
        # Validate data length
25
        if not data or len(data) == 0:
6✔
26
            raise ValueError("Data array cannot be empty")
6✔
27

28
        # Validate whis parameter
29
        if whis <= 0:
6✔
30
            raise ValueError("Whisker length must be positive")
6✔
31

32
        self.data = numeric_data
6✔
33
        self.notch = notch
6✔
34
        self.sym = sym
6✔
35
        self.vert = vert
6✔
36
        self.whis = whis
6✔
37

38
    # Rest of the class implementation remains the same
39
    def median(self):
6✔
40
        """Calculate median of the data"""
41
        return float(np.median(self.data))
6✔
42

43
    def quartiles(self):
6✔
44
        """Calculate first and third quartiles"""
45
        q1 = float(np.percentile(self.data, 25))
6✔
46
        q3 = float(np.percentile(self.data, 75))
6✔
47
        return (q1, q3)
6✔
48

49
    def outliers(self):
6✔
50
        """Identify outliers using whis*IQR rule"""
51
        q1, q3 = self.quartiles()
6✔
52
        iqr = q3 - q1
6✔
53
        lower_bound = q1 - (self.whis * iqr)
6✔
54
        upper_bound = q3 + (self.whis * iqr)
6✔
55
        return [x for x in self.data if x < lower_bound or x > upper_bound]
6✔
56

57
    def plot(self):
6✔
58
        """Generate box plot"""
59
        plt.style.use("_mpl-gallery")
6✔
60
        fig, ax = plt.subplots()
6✔
61

62
        # Set orientation using new parameter name
63
        orientation = "vertical" if self.vert else "horizontal"
6✔
64

65
        # Set ticks properly
66
        if orientation == "vertical":
6✔
67
            ax.set_xticks([1])
6✔
68
            ax.set_xticklabels(["Data"])
6✔
69
        else:
70
            ax.set_yticks([1])
6✔
71
            ax.set_yticklabels(["Data"])
6✔
72

73
        plt.show()
6✔
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