Python Chaco MultiLinePlot-无法显示简单的绘图,不知道包是否损坏?
我正在尝试创建一个多线图,以显示来自2D NumPy阵列的多个时间序列数据(电压)。我已经开始非常简单地尝试从一个2x10数组中用十个数据点绘制两条线,但我甚至无法在没有得到大量错误输出的情况下使其工作,而我无法调试这些错误输出 进口:Python Chaco MultiLinePlot-无法显示简单的绘图,不知道包是否损坏?,python,plot,enthought,chaco,Python,Plot,Enthought,Chaco,我正在尝试创建一个多线图,以显示来自2D NumPy阵列的多个时间序列数据(电压)。我已经开始非常简单地尝试从一个2x10数组中用十个数据点绘制两条线,但我甚至无法在没有得到大量错误输出的情况下使其工作,而我无法调试这些错误输出 进口: import numpy from traits.api import HasTraits, Instance from traitsui.api import View, Item from chaco.api import MultiLinePlot, Ar
import numpy
from traits.api import HasTraits, Instance
from traitsui.api import View, Item
from chaco.api import MultiLinePlot, ArrayDataSource, MultiArrayDataSource
from enable.component_editor import ComponentEditor
测试阵列:
test_array = numpy.random.rand(10,2)
显示类:
class Multi_line_graph(HasTraits):
plot = Instance(MultiLinePlot)
traits_view = View(
Item('plot',editor=ComponentEditor(), show_label=False),
width=1024, height=768, resizable=True, title="EEG Preview")
def __init__(self, my_data):
super(Multi_line_graph, self).__init__()
x = ArrayDataSource(numpy.arange(1, my_data.shape[0]))
y = my_data.transpose() #since my data columnwise
y = MultiArrayDataSource(y)
yidx = ArrayDataSource(numpy.arange(y.get_shape()[0]))
plot = MultiLinePlot(index=x, yindex=yidx, value=y)
self.plot = plot
创建类的实例:
my_graph = Multi_line_graph(test_array)
显示(配置特征):
然后我看到一个窗口出现,但是它挂起并崩溃了Python内核,并且在shell中显示了这个错误:
Exception occurred in traits notification handler for object: <chaco.multi_line_plot.MultiLinePlot object at 0x000000000D0CFD58>, trait: bounds_items, old value: <undefined>, new value: <traits.trait_handlers.TraitListEvent object at 0x000000000D18C908>
Traceback (most recent call last):
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\traits\trait_notifiers.py", line 340, in __call__
self.handler( *args )
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\base_xy_plot.py", line 613, in _bounds_items_changed
self._update_mappers()
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\base_xy_plot.py", line 594, in _update_mappers
x_mapper.screen_bounds = (x, x2)
AttributeError: 'NoneType' object has no attribute 'screen_bounds'
Exception occurred in traits notification handler for object: <chaco.multi_line_plot.MultiLinePlot object at 0x000000000D0CFD58>, trait: bounds_items, old value: <undefined>, new value: <traits.trait_handlers.TraitListEvent object at 0x000000000D0C4C88>
Traceback (most recent call last):
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\traits\trait_notifiers.py", line 340, in __call__
self.handler( *args )
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\base_xy_plot.py", line 613, in _bounds_items_changed
self._update_mappers()
File "C:\Users\pzl46097\AppData\Local\Enthought\Canopy\User\lib\site-packages\chaco\base_xy_plot.py", line 594, in _update_mappers
x_mapper.screen_bounds = (x, x2)
AttributeError: 'NoneType' object has no attribute 'screen_bounds'
Exception occurred in traits notification handler.
Please check the log file for details.
对象的traits通知处理程序中发生异常:,trait:bounds\u项,旧值:,新值:
回溯(最近一次呼叫最后一次):
文件“C:\Users\pzl46097\AppData\Local\enthunk\Canopy\User\lib\site packages\traits\trait\u notifiers.py”,第340行,在\uu调用中__
self.handler(*args)
文件“C:\Users\pzl46097\AppData\Local\enthught\Canopy\User\lib\site packages\chaco\base\u xy\u plot.py”,第613行,已更改
自我更新映射器()
文件“C:\Users\pzl46097\AppData\Local\enthught\Canopy\User\lib\site packages\chaco\base\u xy\u plot.py”,第594行,位于地图更新程序中
x_mapper.screen_界限=(x,x2)
AttributeError:“非类型”对象没有“屏幕边界”属性
对象为、特征为、边界为、旧值为、新值为的特征通知处理程序中出现异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\pzl46097\AppData\Local\enthunk\Canopy\User\lib\site packages\traits\trait\u notifiers.py”,第340行,在\uu调用中__
self.handler(*args)
文件“C:\Users\pzl46097\AppData\Local\enthught\Canopy\User\lib\site packages\chaco\base\u xy\u plot.py”,第613行,已更改
自我更新映射器()
文件“C:\Users\pzl46097\AppData\Local\enthught\Canopy\User\lib\site packages\chaco\base\u xy\u plot.py”,第594行,位于地图更新程序中
x_mapper.screen_界限=(x,x2)
AttributeError:“非类型”对象没有“屏幕边界”属性
通知处理程序中发生异常。
有关详细信息,请查看日志文件。
我真的不知道这意味着什么。我已阅读并重新阅读API文档,网址为:
以及用户指南文档,网址为:
但是似乎没有关于这个类的任何其他文档。我想知道它是否没有被维护,可能会被破坏,或者我做错了什么(我很可能是因为我只使用了大约一周的Chaco,这个库对我来说是新的,就像Python中的OOP一样)
非常感谢您的帮助。不确定您镜像的是什么示例,但是直接使用数据源实例并不是从Chaco开始的最简单的方法 我的建议是使用常规的
Plot
类和ArrayPlotData
类来存储数组。展开一点,假设您有多个时间序列要打印,这里是一个使用不同颜色的多个线打印的工作示例:
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()
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()