Repository: biolab/orange3

Issue:
Combination of Paint Data and Scatter Plot crashes
I am using a combination of Paint Data and Scatterplot to display decision boundaries of the classifiers:

![image](https://user-images.githubusercontent.com/726604/172701653-34ecb4df-edc7-477d-a60b-e6e58ca9dc24.png)
![image](https://user-images.githubusercontent.com/726604/172703390-b2f72d53-1e5d-4c7a-be45-ba03e1cd416f.png)

This often works, but every while it crashes with the following message:

```
Traceback (most recent call last):
  File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/orangewidget/gui.py", line 2236, in __call__
    self.func(**kwds)
  File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Orange/widgets/visualize/owscatterplot.py", line 282, in update_density
    super().update_density()
  File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Orange/widgets/visualize/owscatterplotgraph.py", line 1215, in update_density
    c_data = self.master.get_color_data()
  File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Orange/widgets/visualize/utils/widget.py", line 195, in get_color_data
    return self.get_column(self.attr_color, max_categories=MAX_COLORS)
  File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/Orange/widgets/visualize/utils/widget.py", line 150, in get_column
    all_data = all_data[self.valid_data]
IndexError: boolean index did not match indexed array along dimension 0; dimension is 123 but corresponding boolean dimension is 51
```

**How can we reproduce the problem?** 

Here is the workflow file. Open the Paint Data widget and paint some more data for the system to crash:

[paint-scatterplot-crash.ows.zip](https://github.com/biolab/orange3/files/8864556/paint-scatterplot-crash.ows.zip)

**What's your environment?**

- Operating system: macOS 12.4
- Orange version: 3.32.0
- How you installed Orange: dmg



Discussion:

Resolving patch:
diff --git a/Orange/widgets/visualize/utils/widget.py b/Orange/widgets/visualize/utils/widget.py
--- a/Orange/widgets/visualize/utils/widget.py
+++ b/Orange/widgets/visualize/utils/widget.py
@@ -651,6 +651,7 @@ def sizeHint(self):
     def clear(self):
         self.selection = None
         self.graph.selection = None
+        self.graph.clear()
 
     def onDeleteWidget(self):
         super().onDeleteWidget()


Test patch:
diff --git a/Orange/widgets/visualize/tests/test_owscatterplot.py b/Orange/widgets/visualize/tests/test_owscatterplot.py
--- a/Orange/widgets/visualize/tests/test_owscatterplot.py
+++ b/Orange/widgets/visualize/tests/test_owscatterplot.py
@@ -14,7 +14,7 @@
 from Orange.widgets.tests.base import (
     WidgetTest, WidgetOutputsTestMixin, datasets, ProjectionWidgetTestMixin
 )
-from Orange.widgets.tests.utils import simulate
+from Orange.widgets.tests.utils import simulate, excepthook_catch
 from Orange.widgets.utils.colorpalettes import DefaultRGBColors
 from Orange.widgets.visualize.owscatterplot import (
     OWScatterPlot, ScatterPlotVizRank, OWScatterPlotGraph)
@@ -1130,6 +1130,14 @@ def test_time_axis(self):
         with self.assertRaises(ValueError):
             float(ticks[0])
 
+    def test_clear_plot(self):
+        self.widget.cb_class_density.setChecked(True)
+        self.send_signal(self.widget.Inputs.data, self.data)
+        data = self.data.transform(Domain(self.data.domain.attributes))[:100]
+        self.send_signal(self.widget.Inputs.data, data)
+        with excepthook_catch():
+            self.send_signal(self.widget.Inputs.data, self.data)
+
     def test_visual_settings(self):
         super().test_visual_settings()