Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] OWDistributions: add cumulative distribution #3766

Merged
merged 1 commit into from
Apr 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Orange/widgets/visualize/owdistributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class Inputs:

relative_freq = settings.Setting(False)
disc_cont = settings.Setting(False)
cumulative_distr = settings.Setting(False)

smoothing_index = settings.Setting(5)
show_prob = settings.ContextSetting(0)
Expand Down Expand Up @@ -189,6 +190,10 @@ def __init__(self):
self.varview.selectionModel().selectionChanged.connect(
self._on_variable_idx_changed)
varbox.layout().addWidget(self.varview)
gui.checkBox(
varbox, self, "cumulative_distr", "Cumulative distribution",
callback=self._on_cumulative_distr_changed,
tooltip="Show the cumulative distribution function.")

box = gui.vBox(self.controlArea, "Precision")

Expand Down Expand Up @@ -368,6 +373,7 @@ def _setup(self):
self.var = data.domain[0]
self.set_left_axis_name()
self.enable_disable_rel_freq()
self.controls.cumulative_distr.setDisabled(not self.var.is_continuous)
if self.cvar:
self.contingencies = \
contingency.get_contingency(data, self.var, self.cvar)
Expand Down Expand Up @@ -416,6 +422,9 @@ def display_distribution(self):
smoothing_factor=self.smoothing_factor)
edges = edges + (edges[1] - edges[0])/2
edges = edges[:-1]
if self.cumulative_distr:
dx = edges[1] - edges[0]
curve = numpy.cumsum(curve) * dx
item = pg.PlotCurveItem()
pen = QPen(QBrush(Qt.white), 3)
pen.setCosmetic(True)
Expand Down Expand Up @@ -492,6 +501,9 @@ def display_contingency(self):
X = X[:-1]
X = numpy.array(X)
Y = numpy.array(Y)
if self.cumulative_distr:
dx = X[1] - X[0]
Y = numpy.cumsum(Y) * dx
curvesline.append((X, Y))

for t in ["fill", "line"]:
Expand Down Expand Up @@ -634,6 +646,9 @@ def _on_groupvar_idx_changed(self):
def _on_set_smoothing(self):
self._setup()

def _on_cumulative_distr_changed(self):
self._setup()

def onDeleteWidget(self):
self.plot.clear()
super().onDeleteWidget()
Expand Down