Repository: enthought/chaco

Issue:
Bug in the connected single range example 
**Problem Description**
[Connected single range](https://github.com/enthought/chaco/blob/master/examples/tutorials/scipy2008/connected_single_range.py) example has a bug - left-hand side plot has all its points collapse onto the y-axis.

![screenshot from 2017-12-18 12-30-29](https://user-images.githubusercontent.com/34460026/34121614-44e58854-e3ef-11e7-8eab-43c7b725b1b7.png)
**Reproduction Steps:**
Run the linked example from the newly installed `edm` environment. 

**OS, Python version:**
Ubuntu 16.04, Python 2.7, Chaco 4.7.1



Discussion:
The demo worked in 4.6.1, Python 2 and 3 on macOS.
FWIW, it works on my Ubuntu 16.04 laptop when I revert to Chaco 4.6, but then I get the following warnings:

```
/home/yzaretskiy/.edm/envs/old-chaco/lib/python2.7/site-packages/chaco/array_data_source.py:123: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  self._data = newdata
/home/yzaretskiy/.edm/envs/old-chaco/lib/python2.7/site-packages/chaco/axis.py:498: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  for tickpos in mapped_tick_positions]))
/home/yzaretskiy/.edm/envs/old-chaco/lib/python2.7/site-packages/chaco/axis.py:499: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  self._tick_label_list = tick_list
/home/yzaretskiy/.edm/envs/old-chaco/lib/python2.7/site-packages/chaco/axis.py:500: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  self._tick_label_positions = self._tick_positions
/home/yzaretskiy/.edm/envs/old-chaco/lib/python2.7/site-packages/chaco/scatterplot.py:416: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  self._cached_selected_pts = points
```

Those warnings were also reported in #251.
You can ignore the warnings. They were fixed by #350 which made it into the 4.7.0 release.
Note that the updated range is the one that gets messed up. In this case it's `scatterplot`. Swapping the assignment on [line 42](https://github.com/enthought/chaco/blob/master/examples/tutorials/scipy2008/connected_single_range.py#L42) results in the line plot getting messed up.

Resolving patch:
diff --git a/chaco/plot.py b/chaco/plot.py
--- a/chaco/plot.py
+++ b/chaco/plot.py
@@ -1276,7 +1276,7 @@ def _handle_range_changed(self, name, old, new):
                 if new is not None:
                     new.add(datasource)
         range_name = name + "_range"
-        for renderer in itertools.chain(six.itervalues(self.plots)):
+        for renderer in itertools.chain(*six.itervalues(self.plots)):
             if hasattr(renderer, range_name):
                 setattr(renderer, range_name, new)
 


Test patch:
diff --git a/chaco/tests/plot_test_case.py b/chaco/tests/plot_test_case.py
--- a/chaco/tests/plot_test_case.py
+++ b/chaco/tests/plot_test_case.py
@@ -3,7 +3,7 @@
 from numpy import arange
 
 # Chaco imports
-from chaco.api import ArrayPlotData, Plot
+from chaco.api import ArrayPlotData, Plot, DataRange1D
 
 
 class PlotTestCase(unittest.TestCase):
@@ -18,5 +18,18 @@ def test_plot_from_unsupported_array_shape(self):
         data.update_data(x=arr, y=arr)
         self.assertRaises(ValueError, plot.plot, ("x", "y"))
 
+    def test_range_change(self):
+        arr = arange(10)
+        data = ArrayPlotData(x=arr, y=arr)
+        plot = Plot(data)
+        renderer = plot.plot(('x', 'y'))[0]
+        new_range = DataRange1D()
+        old_range = plot.index_range
+        self.assertIsNot(old_range, new_range)
+        self.assertIs(renderer.index_range, old_range)
+        plot.index_range = new_range
+        self.assertIs(plot.index_range, new_range)
+        self.assertIs(renderer.index_range, new_range)
+
 if __name__ == "__main__":
     unittest.main()