Skip to content

Commit ce42413

Browse files
authored
feat: support boxplot using maidr-ts (#151)
1 parent 9e57a7c commit ce42413

File tree

5 files changed

+21
-82
lines changed

5 files changed

+21
-82
lines changed

Diff for: example/box/matplotlib/example_mpl_box.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import maidr
55

6+
maidr.set_engine("ts")
7+
68
# Generating random data for three different groups
79
data_group1 = np.random.normal(100, 10, 200)
810
data_group2 = np.random.normal(90, 20, 200)
@@ -40,7 +42,7 @@ def boxplot(is_vert: bool):
4042
# plt.show()
4143
maidr.show(vert)
4244

43-
# Create the vertical boxplot
45+
# Create the horizontal boxplot
4446
horz = boxplot(is_vert=False)
4547
# plt.show()
4648
maidr.show(horz)

Diff for: example/box/seaborn/example_sns_box.py

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import maidr
55

6+
maidr.set_engine("ts")
7+
68
# Load the Iris dataset
79
iris = sns.load_dataset("iris")
810

Diff for: maidr/core/enum/maidr_key.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class MaidrKey(str, Enum):
2222
TITLE = "title"
2323

2424
# Box plot keys.
25-
LOWER_OUTLIER = "lower_outlier"
25+
LOWER_OUTLIER = "lowerOutliers"
2626
MIN = "min"
2727
MAX = "max"
2828
Q1 = "q1"
2929
Q2 = "q2"
3030
Q3 = "q3"
31-
UPPER_OUTLIER = "upper_outlier"
31+
UPPER_OUTLIER = "upperOutliers"
3232

3333
# Grouped bar and heatmap plot keys.
3434
FILL = "fill"

Diff for: maidr/core/plot/boxplot.py

+14-20
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ def render(self) -> dict:
138138
box_orientation = {MaidrKey.ORIENTATION: self._orientation}
139139
return DictMergerMixin.merge_dict(base_schema, box_orientation)
140140

141-
def _extract_axes_data(self) -> dict:
142-
base_ax_schema = super()._extract_axes_data()
143-
if self._orientation == "vert":
144-
box_ax_schema = {
145-
MaidrKey.X: {
146-
MaidrKey.LEVEL: self.extract_level(self.ax, MaidrKey.X),
147-
},
148-
}
149-
else:
150-
box_ax_schema = {
151-
MaidrKey.Y: {
152-
MaidrKey.LEVEL: self.extract_level(self.ax, MaidrKey.Y),
153-
}
154-
}
155-
return self.merge_dict(base_ax_schema, box_ax_schema)
156-
157141
def _extract_plot_data(self) -> list:
158142
data = self._extract_bxp_maidr(self._bxp_stats)
159143

@@ -171,17 +155,27 @@ def _extract_bxp_maidr(self, bxp_stats: dict) -> list[dict] | None:
171155
caps = self._bxp_extractor.extract_caps(bxp_stats["caps"])
172156
medians = self._bxp_extractor.extract_medians(bxp_stats["medians"])
173157
outliers = self._bxp_extractor.extract_outliers(bxp_stats["fliers"], caps)
174-
175-
for whisker, cap, median, outlier in zip(whiskers, caps, medians, outliers):
158+
levels = (
159+
self.extract_level(self.ax, MaidrKey.X)
160+
if self._orientation == "vert"
161+
else self.extract_level(self.ax, MaidrKey.Y)
162+
)
163+
if levels is None:
164+
levels = []
165+
166+
for whisker, cap, median, outlier, level in zip(
167+
whiskers, caps, medians, outliers, levels
168+
):
176169
bxp_maidr.append(
177170
{
178-
MaidrKey.LOWER_OUTLIER.value: outlier["lower_outlier"],
171+
MaidrKey.LOWER_OUTLIER.value: outlier[MaidrKey.LOWER_OUTLIER.value],
179172
MaidrKey.MIN.value: cap["min"],
180173
MaidrKey.Q1.value: whisker["q1"],
181174
MaidrKey.Q2.value: median,
182175
MaidrKey.Q3.value: whisker["q3"],
183176
MaidrKey.MAX.value: cap["max"],
184-
MaidrKey.UPPER_OUTLIER.value: outlier["upper_outlier"],
177+
MaidrKey.UPPER_OUTLIER.value: outlier[MaidrKey.UPPER_OUTLIER.value],
178+
MaidrKey.FILL.value: level,
185179
}
186180
)
187181

Diff for: tests/core/plot/test_boxplot.py

-59
This file was deleted.

0 commit comments

Comments
 (0)