enthought / chaco

Chaco is a Python package for building interactive and custom 2-D plots.
http://docs.enthought.com/chaco/
Other
292 stars 99 forks source link

Bar plot disappears and "Exceeded cell block limit" traceback when encountering NaN #845

Closed nicolasap-dm closed 1 year ago

nicolasap-dm commented 1 year ago

Problem Description

When plotting (type="bar") data with NaN, the plot goes blank and a traceback is emitted at paint-time.

Reproduction Steps:

import numpy
from enable.api import ComponentEditor
from traits.api import *
from traitsui.api import *
from chaco.api import *
from chaco.tools.api import *

class PlotExample(HasTraits):
    plot = Instance(Plot)

    def _plot_default(self):
        index = numpy.arange(10.)
        series = index * 10
        series[-1] = float("nan")
        plot_data = ArrayPlotData(index=index)
        plot_data.set_data("series", series)
        plot = Plot(plot_data)
        plot.plot(("index", "series"), type="bar", bar_width=0.8)

        # optional: NaN is initially out of the visible range, so it only crashes upon panning
        plot.index_range.low_setting = -0.5
        plot.index_range.high_setting = 6.5
        plot.tools.append(PanTool(plot, constrain=True, constrain_direction="x"))
        return plot

    traits_view = View(
        UItem("plot", editor=ComponentEditor()),
        width=400, height=400, resizable=True,
    )

demo = PlotExample()
demo.configure_traits()

chaco_crash

Expected behavior:

(For instance) Emit a warning when NaNs are encountered in bar plot data, possibly not at paint-time but as soon as the plot data is updated with offending values. Then avoid plotting the corresponding bar.

OS, Python version: [Enter OS name and Python version]

Python 3.8, OS irrelevant, backend agg.

corranwebster commented 1 year ago

Correct behaviour based on other plot types with NaN values is that they should be skipped.