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

ac-i2i-engineering / MatPlus / 13486214877

23 Feb 2025 07:30PM UTC coverage: 84.783% (-2.9%) from 87.727%
13486214877

Pull #9

github

BestLocation
fix errors with files
Pull Request #9: Added boxplot and tests

58 of 69 new or added lines in 2 files covered. (84.06%)

273 of 322 relevant lines covered (84.78%)

6.97 hits per line

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

66.67
/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
        if not data or len(data) == 0:
6✔
15
            raise ValueError("Data array cannot be empty")
6✔
16

17
        self.data = data
6✔
18
        self.notch = notch
6✔
19
        self.sym = sym
6✔
20
        self.vert = vert
6✔
21
        self.whis = whis
6✔
22

23
    def median(self):
6✔
24
        """Calculate median of the data"""
NEW
25
        return float(np.median(self.data))
×
26

27
    def quartiles(self):
6✔
28
        """Calculate first and third quartiles"""
NEW
29
        q1 = float(np.percentile(self.data, 25))
×
NEW
30
        q3 = float(np.percentile(self.data, 75))
×
NEW
31
        return (q1, q3)
×
32

33
    def outliers(self):
6✔
34
        """Identify outliers using whis*IQR rule"""
NEW
35
        q1, q3 = self.quartiles()
×
NEW
36
        iqr = q3 - q1
×
NEW
37
        lower_bound = q1 - (self.whis * iqr)
×
NEW
38
        upper_bound = q3 + (self.whis * iqr)
×
NEW
39
        return [x for x in self.data if x < lower_bound or x > upper_bound]
×
40

41
    def plot(self):
6✔
42
        """Generate box plot"""
43
        plt.style.use("_mpl-gallery")
6✔
44
        fig, ax = plt.subplots()
6✔
45

46
        # Set orientation using new parameter name
47
        orientation = "vertical" if self.vert else "horizontal"
6✔
48

49
        # Set ticks properly
50
        if orientation == "vertical":
6✔
51
            ax.set_xticks([1])
6✔
52
            ax.set_xticklabels(["Data"])
6✔
53
        else:
NEW
54
            ax.set_yticks([1])
×
NEW
55
            ax.set_yticklabels(["Data"])
×
56

57
        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