Skip to content

Commit 95bb2bb

Browse files
committed
OWBoxPlot: Plot missing values
1 parent 5febf5f commit 95bb2bb

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Orange/statistics/contingency.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def __getitem__(self, index):
125125
if isinstance(index[1], str):
126126
index = (index[0], self.col_variable.to_val(index[1]))
127127
result = super().__getitem__(index)
128+
if isinstance(index, int) or len(index) == 1:
129+
result.unknowns = self.unknowns[index]
128130
if result.strides:
129131
result.col_variable = self.col_variable
130132
result.row_variable = self.row_variable

Orange/statistics/distribution.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ def max(self):
211211
if self.variable.ordered:
212212
return self.variable.values[-1]
213213

214+
def sum(self, *args, **kwargs):
215+
res = super().sum(*args, **kwargs)
216+
res.unknowns = self.unknowns
217+
return res
218+
214219

215220
class Continuous(Distribution):
216221
def __new__(cls, dat, variable=None, unknowns=None):

Orange/widgets/visualize/owboxplot.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -987,15 +987,18 @@ def line(x0, y0, x1, y1, *args):
987987

988988
def strudel(self, dist, group_val_index=None):
989989
attr = self.attribute
990-
ss = np.sum(dist)
990+
ss = np.sum(dist) + dist.unknowns
991991
box = []
992992
if ss < 1e-6:
993993
cond = [FilterDiscrete(attr, None)]
994994
if group_val_index is not None:
995995
cond.append(FilterDiscrete(self.group_var, [group_val_index]))
996996
box.append(FilterGraphicsRectItem(cond, 0, -10, 1, 10))
997997
cum = 0
998-
for i, v in enumerate(dist):
998+
values = attr.values + ["Missing values"]
999+
colors = np.vstack((attr.colors, [128, 128, 128]))
1000+
dist_unk = np.append(dist, dist.unknowns)
1001+
for i, v in enumerate(dist_unk):
9991002
if v < 1e-6:
10001003
continue
10011004
if self.stretched:
@@ -1005,15 +1008,16 @@ def strudel(self, dist, group_val_index=None):
10051008
if group_val_index is not None:
10061009
cond.append(FilterDiscrete(self.group_var, [group_val_index]))
10071010
rect = FilterGraphicsRectItem(cond, cum + 1, -6, v - 2, 12)
1008-
rect.setBrush(QBrush(QColor(*attr.colors[i])))
1011+
rect.setBrush(QBrush(QColor(*colors[i])))
10091012
rect.setPen(QPen(Qt.NoPen))
10101013
if self.stretched:
1011-
tooltip = "{}: {:.2f}%".format(attr.values[i],
1012-
100 * dist[i] / sum(dist))
1014+
tooltip = "{}: {:.2f}%".format(
1015+
values[i],
1016+
100 * dist_unk[i] / sum(dist_unk))
10131017
else:
1014-
tooltip = "{}: {}".format(attr.values[i], int(dist[i]))
1018+
tooltip = "{}: {}".format(values[i], int(dist_unk[i]))
10151019
rect.setToolTip(tooltip)
1016-
text = QGraphicsTextItem(attr.values[i])
1020+
text = QGraphicsTextItem(values[i])
10171021
box.append(rect)
10181022
box.append(text)
10191023
cum += v

0 commit comments

Comments
 (0)