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

ac-i2i-engineering / MatPlus / 13743029525

09 Mar 2025 12:38AM UTC coverage: 94.444% (+0.02%) from 94.424%
13743029525

Pull #13

github

liamjdavis
Re-styled source code
Pull Request #13: Added New RSTs for Docs

2 of 2 new or added lines in 2 files covered. (100.0%)

1 existing line in 1 file now uncovered.

510 of 540 relevant lines covered (94.44%)

8.25 hits per line

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

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

4

5
class BoxPlot:
6✔
6
    """
1✔
7
    A class to create box plots with optional notches, symbols for outliers, and vertical orientation.
8

9
    Attributes:
10
    ----------
11
    data : array-like
12
        The data to be plotted.
13
    notch : bool, optional
14
        Whether to draw a notch to indicate the confidence interval around the median. Default is False.
15
    sym : str, optional
16
        The symbol for outliers. Default is "b".
17
    vert : bool, optional
18
        Whether to draw the box plot vertically. Default is True.
19
    whis : float, optional
20
        The length of the whiskers as a multiple of the interquartile range (IQR). Default is 1.5.
21
    """
22
    def __init__(self, data, notch=False, sym="b", vert=True, whis=1.5):
6✔
23
        # Validate data type
24
        if not isinstance(data, (list, np.ndarray)):
6✔
UNCOV
25
            raise TypeError("Data must be a list or numpy array")
×
26

27
        # Validate numeric data
28
        try:
6✔
29
            numeric_data = [float(x) for x in data]
6✔
30
        except (ValueError, TypeError):
6✔
31
            raise TypeError("All elements must be numeric")
6✔
32

33
        # Validate data length
34
        if not data or len(data) == 0:
6✔
35
            raise ValueError("Data array cannot be empty")
6✔
36

37
        # Validate whis parameter
38
        if whis <= 0:
6✔
39
            raise ValueError("Whisker length must be positive")
6✔
40

41
        self.data = numeric_data
6✔
42
        self.notch = notch
6✔
43
        self.sym = sym
6✔
44
        self.vert = vert
6✔
45
        self.whis = whis
6✔
46

47
    # Rest of the class implementation remains the same
48
    def median(self):
6✔
49
        """Calculate median of the data"""
50
        return float(np.median(self.data))
6✔
51

52
    def quartiles(self):
6✔
53
        """Calculate first and third quartiles"""
54
        q1 = float(np.percentile(self.data, 25))
6✔
55
        q3 = float(np.percentile(self.data, 75))
6✔
56
        return (q1, q3)
6✔
57

58
    def outliers(self):
6✔
59
        """Identify outliers using whis*IQR rule"""
60
        q1, q3 = self.quartiles()
6✔
61
        iqr = q3 - q1
6✔
62
        lower_bound = q1 - (self.whis * iqr)
6✔
63
        upper_bound = q3 + (self.whis * iqr)
6✔
64
        return [x for x in self.data if x < lower_bound or x > upper_bound]
6✔
65

66
    def plot(self):
6✔
67
        """Generate box plot"""
68
        plt.style.use("_mpl-gallery")
6✔
69
        fig, ax = plt.subplots()
6✔
70

71
        # Set labels and ticks
72
        if self.vert:
6✔
73
            ax.set_xlabel("Data")
6✔
74
            ax.set_ylabel("Value")
6✔
75
            ax.set_xticks([1])
6✔
76
        else:
77
            ax.set_xlabel("Value")
6✔
78
            ax.set_ylabel("Data")
6✔
79
            ax.set_yticks([1])
6✔
80

81
        # Add grid for better readability
82
        ax.grid(True, linestyle="--", alpha=0.7)
6✔
83

84
        # Adjust layout to prevent label clipping
85
        plt.tight_layout()
6✔
86

87
        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