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

Empty chaco plot crashes when clicked on #529

Closed
sandhya-sago opened this issue Oct 1, 2020 · 2 comments · Fixed by #636
Closed

Empty chaco plot crashes when clicked on #529

sandhya-sago opened this issue Oct 1, 2020 · 2 comments · Fixed by #636
Assignees

Comments

@sandhya-sago
Copy link

sandhya-sago commented Oct 1, 2020

Problem Description
Clicking on an empty chaco plot results in a crash. In our usage, an empty chaco plot is created first, and later data is added.
Reproduction Steps:

class LinePlot(HasTraits):
    plot = Instance(Plot)
    x = []
    y = []
    traits_view = View(
            Item('plot', editor=ComponentEditor(),
                 show_label=False),
            width=500, height=500,
            resizable=True,
            title="Chaco Plot")
    def _plot_default(self):
        # Create the data and the PlotData object
        # Create a Plot and associate it with the PlotData
        plot = Plot(ArrayPlotData(x=self.x, y=self.y))
        # Create a line plot in the Plot
        plot.plot(("x", "y"), type="line", color="blue")
        # Set the title and label the x-axis
        plot.title = "sin(x) * x^3"
        plot.x_axis.title = "x-axis label"
        plot.tools.append(PanTool(plot))
        plot.overlays.append(ZoomTool(plot, zoom_fator=1.1))
        # Assign it to our self.plot attribute
        return plot
demo = LinePlot()
demo.configure_traits()

Once the plot comes up, try clicking on it. It crashes with the following traceback (full path has been replaced with <>).

Traceback (most recent call last):
  File "<>/lib/python3.6/site-packages/enable/qt4/base_window.py", line 213, in paintEvent
    self.handler.paintEvent(event)
  File "<>/lib/python3.6/site-packages/enable/qt4/base_window.py", line 65, in paintEvent
    self._enable_window._paint(event)
  File "<>/lib/python3.6/site-packages/enable/abstract_window.py", line 471, in _paint
    self.component.draw(gc, view_bounds=(0, 0, size[0], size[1]))
  File "<>/lib/python3.6/site-packages/enable/component.py", line 427, in draw
    self._draw(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/component.py", line 779, in _draw
    self._dispatch_draw(layer, gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 273, in _dispatch_draw
    component._dispatch_draw(layer, gc, new_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 258, in _dispatch_draw
    my_handler(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 298, in _draw_container_underlay
    self._draw_underlay(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/component.py", line 887, in _draw_underlay
    underlay.overlay(self, gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/chaco/grid.py", line 307, in overlay
    self._compute_ticks(other_component)
  File "<>/lib/python3.6/site-packages/chaco/grid.py", line 255, in _compute_ticks
    scale=scale)
  File "<>/lib/python3.6/site-packages/chaco/ticks.py", line 84, in get_ticks
    interval, use_endpoints=False), float64)
  File "<>/lib/python3.6/site-packages/chaco/ticks.py", line 216, in auto_ticks
    ticks = arange( start, end + (tick_interval / 2.0), tick_interval )
ValueError: arange: cannot compute length

Expected behavior:

No crash when an empty plot is clicked. After data is added, Zoom and Pan work.

OS, Python version: [Enter OS name and Python version]
Python 3.6, MacOS Catalina 10.15.6
chaco 4.8.0-4
enable 4.8.1-5

@xamcost
Copy link

xamcost commented Feb 4, 2021

@sandhya-sago I encountered this issue as well. A workaround, not elegant at all, is to append zoom and pan tools to your components/overlays after plotting some data: if you have a function to update your plot data, you can put in it something like:

if self._zoom_tool not in self._plot.overlays:
    self._plot.overlays.append(self._zoom_tool)

Definitely not elegant, but prevents the crash.

@aaronayres35
Copy link
Contributor

At its core I believe this is really an issue with the Tools not playing nice with edge cases. Even so, there should be other safety checks in place elsewhere so that a crash like this doesn't happen. #636 adds one such check. Other PRs can follow to deal with the issue closer to the true source. (i.e. auto_ticks should really never be getting a NaN in the first place, but if it does it shouldn't cause a crash)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants