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

ac-i2i-engineering / MatPlus / 13486367011

23 Feb 2025 07:52PM UTC coverage: 92.428% (+4.7%) from 87.727%
13486367011

push

github

web-flow
Merge pull request #9 from ac-i2i-engineering/inprogress-surya

Added boxplot and tests

118 of 119 new or added lines in 2 files covered. (99.16%)

354 of 383 relevant lines covered (92.43%)

7.74 hits per line

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

97.73
/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 labels and ticks
63
        if self.vert:
6✔
64
            ax.set_xlabel("Data")
6✔
65
            ax.set_ylabel("Value")
6✔
66
            ax.set_xticks([1])
6✔
67
        else:
68
            ax.set_xlabel("Value")
6✔
69
            ax.set_ylabel("Data")
6✔
70
            ax.set_yticks([1])
6✔
71

72
        # Add grid for better readability
73
        ax.grid(True, linestyle="--", alpha=0.7)
6✔
74

75
        # Adjust layout to prevent label clipping
76
        plt.tight_layout()
6✔
77

78
        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