3
This plot displays chaco's ability to handle data interlaced with NaNs.
4
- Left-drag pans the plot.
5
- Mousewheel up and down zooms the plot in and out.
6
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
7
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
8
and alt-right-arrow moves you forwards and backwards through the "zoom
12
# Major library imports
13
from numpy import linspace, nan
14
from scipy.special import jn
16
# Enthought library imports
17
from enable.api import Component, ComponentEditor
18
from traits.api import HasTraits, Instance
19
from traitsui.api import Item, Group, View
22
from chaco.api import ArrayPlotData, Plot
23
from chaco.tools.api import PanTool, ZoomTool
25
#===============================================================================
26
# # Create the Chaco plot.
27
#===============================================================================
28
def _create_plot_component():
30
# Create some x-y data series (with NaNs) to plot
31
x = linspace(-5.0, 15.0, 500)
35
pd = ArrayPlotData(index = x)
36
pd.set_data("value1", jn(0, x))
37
pd.set_data("value2", jn(1, x))
39
# Create some line and scatter plots of the data
41
plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0)
42
plot.plot(("index", "value2"), type="scatter", marker_size=1,
43
name="j_1(x)", color="green")
45
# Tweak some of the plot properties
46
plot.title = "Plots with NaNs"
48
plot.legend.visible = True
50
# Attach some tools to the plot
51
plot.tools.append(PanTool(plot))
52
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
53
plot.overlays.append(zoom)
57
#===============================================================================
58
# Attributes to use for the plot view.
62
#===============================================================================
63
# # Demo class that is used by the demo.py application.
64
#===============================================================================
65
class Demo(HasTraits):
66
plot = Instance(Component)
70
Item('plot', editor=ComponentEditor(size=size),
72
orientation = "vertical"),
73
resizable=True, title=title
76
def _plot_default(self):
77
return _create_plot_component()
81
if __name__ == "__main__":
82
demo.configure_traits()