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

« back to all changes in this revision

Viewing changes to examples/demo/basic/bounded_grids.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
 
#!/usr/bin/env python
2
 
"""
3
 
Demonstrates how to limit the extent of grid lines
4
 
"""
5
 
 
6
 
# Major library imports
7
 
from numpy import array, linspace, zeros
8
 
from scipy.special import jn
9
 
 
10
 
# Enthought library imports
11
 
from enable.api import Component, ComponentEditor
12
 
from traits.api import HasTraits, Instance
13
 
from traitsui.api import Item, Group, View
14
 
 
15
 
# Chaco imports
16
 
from chaco.api import ArrayPlotData, HPlotContainer, Plot
17
 
from chaco.tools.api import PanTool, ZoomTool
18
 
 
19
 
#===============================================================================
20
 
# # Create the Chaco plot.
21
 
#===============================================================================
22
 
def _create_plot_component():
23
 
 
24
 
    # Create some x-y data series to plot
25
 
    x = linspace(-2.0, 10.0, 100)
26
 
    pd = ArrayPlotData(index = x)
27
 
    for i in range(5):
28
 
        pd.set_data("y" + str(i), jn(i,x))
29
 
 
30
 
    # Create some line plots of some of the data
31
 
    plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
32
 
    plot.legend.visible = True
33
 
    plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto")
34
 
    plot.plot(("index", "y3"), name="j_3", color="auto")
35
 
 
36
 
    plot.x_grid.line_color = "black"
37
 
    plot.y_grid.line_color = "black"
38
 
    xmin, xmax = 1.0, 6.0
39
 
    ymin, ymax = 0.2, 0.80001
40
 
    plot.x_grid.set(data_min = xmin, data_max = xmax,
41
 
            transverse_bounds = (ymin, ymax),
42
 
            transverse_mapper = plot.y_mapper)
43
 
 
44
 
    plot.y_grid.set(data_min = ymin, data_max = ymax,
45
 
            transverse_bounds = (xmin, xmax),
46
 
            transverse_mapper = plot.x_mapper)
47
 
 
48
 
    # Attach some tools to the plot
49
 
    plot.tools.append(PanTool(plot))
50
 
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
51
 
    plot.overlays.append(zoom)
52
 
 
53
 
    # A second plot whose vertical grid lines are clipped to the jn(3) function
54
 
    def my_bounds_func(ticks):
55
 
        """ Returns y_low and y_high for each grid tick in the array **ticks** """
56
 
        tmp = array([zeros(len(ticks)),jn(3, ticks)]).T
57
 
        return tmp
58
 
 
59
 
    func_plot = Plot(pd, padding=50, border_visible=True)
60
 
    func_plot.plot(("index", "y3"), color="red")
61
 
    func_plot.x_grid.set(transverse_bounds = my_bounds_func,
62
 
                    transverse_mapper = func_plot.y_mapper,
63
 
                    line_color="black")
64
 
    func_plot.tools.append(PanTool(func_plot))
65
 
 
66
 
    container = HPlotContainer()
67
 
    container.add(plot)
68
 
    container.add(func_plot)
69
 
 
70
 
    return container
71
 
 
72
 
#===============================================================================
73
 
# Attributes to use for the plot view.
74
 
size=(900,500)
75
 
title="Grids with bounded extents"
76
 
 
77
 
#===============================================================================
78
 
# # Demo class that is used by the demo.py application.
79
 
#===============================================================================
80
 
class Demo(HasTraits):
81
 
    plot = Instance(Component)
82
 
 
83
 
    traits_view = View(
84
 
                    Group(
85
 
                        Item('plot', editor=ComponentEditor(size=size),
86
 
                             show_label=False),
87
 
                        orientation = "vertical"),
88
 
                    resizable=True, title=title
89
 
                    )
90
 
 
91
 
    def _plot_default(self):
92
 
         return _create_plot_component()
93
 
 
94
 
demo = Demo()
95
 
 
96
 
if __name__ == "__main__":
97
 
    demo.configure_traits()
98