2
This example creates a simple 1D function examiner, illustrating the use of
3
ChacoPlotEditors for displaying simple plot relations, as well as TraitsUI
4
integration. Any 1D numpy/scipy.special function should work in the function
6
- Left-drag pans the plot.
7
- Mousewheel up and down zooms the plot in and out.
8
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
9
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
10
and alt-right-arrow moves you forwards and backwards through the "zoom
14
# Major library imports
15
from numpy import linspace, pi
17
# Enthought library imports
18
from traits.api import Array, Dict, Enum, HasTraits, Str
19
from traitsui.api import Item, View
22
from chaco.chaco_plot_editor import ChacoPlotEditor, \
30
plot_type = Enum("scatter", "line")
33
# Default TraitsUI view
35
ChacoPlotItem("xdata", "_ydata",
36
type_trait="plot_type",
38
# Basic axis and label properties
42
x_label = "Index data",
43
y_label = "Value data",
49
# Specific to scatter plot
52
outline_color = "none",
54
# Border, padding properties
57
padding_bg_color = "lightgray"),
61
width=500, height=500)
68
def __init__(self, **kwtraits):
69
super(Foo, self).__init__(**kwtraits)
70
self._d = dict(x=self.xdata)
71
exec "from scipy import *" in self._d
72
exec "from scipy.special import *" in self._d
73
self._ydata = eval(self.eq, self._d)
75
def _eq_changed(self, old, new):
77
self._ydata = eval(new, self._d)
81
#===============================================================================
82
# # demo object that is used by the demo.py application.
83
#===============================================================================
84
demo = Foo(xdata=linspace(-2*pi, 2*pi ,100), eq="sin(x)")
86
if __name__ == "__main__":
87
demo.edit_traits(kind="modal")