~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/demo/basic/traits_editor.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
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
5
 
text box.
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
11
 
   history".
12
 
"""
13
 
 
14
 
# Major library imports
15
 
from numpy import linspace, pi
16
 
 
17
 
# Enthought library imports
18
 
from traits.api import Array, Dict, Enum, HasTraits, Str
19
 
from traitsui.api import Item, View
20
 
 
21
 
# Chaco imports
22
 
from chaco.chaco_plot_editor import ChacoPlotEditor, \
23
 
                                                ChacoPlotItem
24
 
 
25
 
 
26
 
class Foo(HasTraits):
27
 
 
28
 
    # Public Traits
29
 
    xdata = Array
30
 
    plot_type = Enum("scatter", "line")
31
 
    eq = Str("sin(x)")
32
 
 
33
 
    # Default TraitsUI view
34
 
    traits_view = View(
35
 
                       ChacoPlotItem("xdata", "_ydata",
36
 
                                      type_trait="plot_type",
37
 
 
38
 
                                      # Basic axis and label properties
39
 
                                      show_label=False,
40
 
                                      resizable=True,
41
 
                                      orientation="h",
42
 
                                      x_label = "Index data",
43
 
                                      y_label = "Value data",
44
 
 
45
 
                                      # Plot properties
46
 
                                      color = "green",
47
 
                                      bgcolor = "white",
48
 
 
49
 
                                      # Specific to scatter plot
50
 
                                      marker = "circle",
51
 
                                      marker_size = 2,
52
 
                                      outline_color = "none",
53
 
 
54
 
                                      # Border, padding properties
55
 
                                      border_visible=True,
56
 
                                      border_width=1,
57
 
                                      padding_bg_color = "lightgray"),
58
 
                Item("plot_type"),
59
 
                Item("eq"),
60
 
                resizable=True,
61
 
                width=500, height=500)
62
 
 
63
 
 
64
 
    # Private Traits
65
 
    _d = Dict
66
 
    _ydata = Array
67
 
 
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)
74
 
 
75
 
    def _eq_changed(self, old, new):
76
 
        try:
77
 
            self._ydata = eval(new, self._d)
78
 
        except:
79
 
            pass
80
 
 
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)")
85
 
 
86
 
if __name__ == "__main__":
87
 
    demo.edit_traits(kind="modal")