enthought / enthought/chaco

Some plot types "hang" on NaN data

Open
#373 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
305
Forks
97
PR merge metrics
No merged PRs in 30d

Description

From discussion offline:

Some plot types (FilledLinePlot and PolygonPlot being the ones that I tested) don’t do well with NaN data. If you try to plot a line or polygon where one of the coordinates is NaN, the application will hang (the NaN gets converted somewhere in Agg to some obscenely large integer, and Agg will keep itself busy trying to draw a line to that faraway location).

@corranwebster's answer:
Yes - it would be better to raise a `ValueError` or something than hang.

Another possibility which would match behaviour of line plots would be to break into runs of non-NaN values and then draw a separate polygon for each. That might give some odd results, though, and would require some re-working of the code.

Final possibility would be to just drop the NaN values silently before calling the rendering code.

@rkern's answer:

Yeah, the Chaco renderers have the responsibility of cleaning the data of non-finite (or even just out-of-bbox) data before creating the view-space coordinates that are given to the GC. It's mostly obvious how to do that for lines and points, but a little less obvious how to do that for polygons, so I suspect a simple sin of omission there.

The `_gather_points()` method is typically where this is done.

---
The code below will hang:

```python
import numpy as np

from enable.api import Component, ComponentEditor
from traits.api import HasStrictTraits, Instance
from traitsui.api import UItem, View
from chaco.api import ArrayPlotData, Plot

class Demo(HasStrictTraits):

view = View(UItem('plot', editor=ComponentEditor()))
plot = Instance(Component)

def _plot_default(self):
edges = np.linspace(0, 1, 10)
hist = np.full(edges.shape[0], 0)
hist[5] = np.nan

plot_data = ArrayPlotData(hh_hist=hist, hh_edges=edges)
plot = Plot(plot_data)
plot.plot(
('hh_edges', 'hh_hist'),
type='filled_line',
render_style='connectedhold',
fill_color='black',
alpha=0.5,
)
return plot

if __name__ == '__main__':
Demo().configure_traits()
```

**OS, Python version:** Tested under Python 2.7 on Mac OS X 10.11 and Linux (Ubuntu 14.04)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.