Chaco MultiLinePlot - unable to get simple plot to display, wondering if package broken?

冷暖自知 提交于 2019-12-04 17:15:54

Not sure what example you were mirroring, but working directly with DataSource instances isn't the easiest way to start with Chaco.

My suggestion is to use the regular Plot class and the ArrayPlotData class to store your arrays. Expanding a bit, and assuming you have multiple timeseries to plot here is a working example with multiple line plots with different colors:

import numpy 
from traits.api import Array, HasTraits, Instance 
from traitsui.api import View, Item 
from chaco.api import ArrayPlotData, Plot 
from enable.api import ComponentEditor

test_array = numpy.random.rand(10, 2)    

class Multi_line_graph(HasTraits):

    plot = Instance(Plot)

    data = Array

    traits_view = View(
        Item('plot', editor=ComponentEditor(), show_label=False),
        width=1024, height=768, resizable=True, title="EEG Preview"
    )

    def _plot_default(self):
        data = {"x": t_array[0, :], "y1": t_array[1, :], "y2": t_array[2, :]}
        plot = Plot(ArrayPlotData(**data))
        plot.plot(("x", "y1"), type="line", color="blue")
        plot.plot(("x", "y2"), type="line", color="red")
        return plot

my_graph = Multi_line_graph(data=test_array)
my_graph.configure_traits()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!