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

« back to all changes in this revision

Viewing changes to examples/demo/basic/inset_plot.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
 
A modification of line_plot1.py that shows the second plot as a subwindow
4
 
of the first.  You can pan and zoom the second plot just like the first,
5
 
and you can move it around my right-click and dragging in the smaller plot.
6
 
"""
7
 
 
8
 
# Major library imports
9
 
from numpy import linspace
10
 
from scipy.special import jn
11
 
 
12
 
# Enthought library imports
13
 
from enable.api import Component, ComponentEditor
14
 
from traits.api import HasTraits, Instance
15
 
from traitsui.api import Item, Group, View
16
 
 
17
 
# Chaco imports
18
 
from chaco.api import ArrayPlotData, OverlayPlotContainer, Plot
19
 
from chaco.tools.api import PanTool, ZoomTool, MoveTool
20
 
 
21
 
#===============================================================================
22
 
# # Create the Chaco plot.
23
 
#===============================================================================
24
 
def _create_plot_component():
25
 
    # Create some x-y data series to plot
26
 
    x = linspace(-2.0, 10.0, 100)
27
 
    pd = ArrayPlotData(index = x)
28
 
    for i in range(5):
29
 
        pd.set_data("y" + str(i), jn(i,x))
30
 
 
31
 
    # Create some line plots of some of the data
32
 
    plot1 = Plot(pd)
33
 
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
34
 
    plot1.plot(("index", "y3"), name="j_3", color="blue")
35
 
 
36
 
    # Tweak some of the plot properties
37
 
    plot1.title = "Inset Plot"
38
 
    plot1.padding = 50
39
 
 
40
 
    # Attach some tools to the plot
41
 
    plot1.tools.append(PanTool(plot1))
42
 
    zoom = ZoomTool(component=plot1, tool_mode="box", always_on=False)
43
 
    plot1.overlays.append(zoom)
44
 
 
45
 
    # Create a second scatter plot of one of the datasets, linking its
46
 
    # range to the first plot
47
 
    plot2 = Plot(pd, range2d=plot1.range2d, padding=50)
48
 
    plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")
49
 
    plot2.set(resizable = "",
50
 
              bounds = [250, 250],
51
 
              position = [550,150],
52
 
              bgcolor = "white",
53
 
              border_visible = True,
54
 
              unified_draw = True
55
 
              )
56
 
    plot2.tools.append(PanTool(plot2))
57
 
    plot2.tools.append(MoveTool(plot2, drag_button="right"))
58
 
    zoom = ZoomTool(component=plot2, tool_mode="box", always_on=False)
59
 
    plot2.overlays.append(zoom)
60
 
 
61
 
    # Create a container and add our plots
62
 
    container = OverlayPlotContainer()
63
 
    container.add(plot1)
64
 
    container.add(plot2)
65
 
    return container
66
 
 
67
 
#===============================================================================
68
 
# Attributes to use for the plot view.
69
 
size=(900,500)
70
 
title="Inset plots"
71
 
 
72
 
#===============================================================================
73
 
# # Demo class that is used by the demo.py application.
74
 
#===============================================================================
75
 
class Demo(HasTraits):
76
 
    plot = Instance(Component)
77
 
 
78
 
    traits_view = View(
79
 
                    Group(
80
 
                        Item('plot', editor=ComponentEditor(size=size),
81
 
                             show_label=False),
82
 
                        orientation = "vertical"),
83
 
                    resizable=True, title=title
84
 
                    )
85
 
 
86
 
    def _plot_default(self):
87
 
         return _create_plot_component()
88
 
 
89
 
demo = Demo()
90
 
 
91
 
if __name__ == "__main__":
92
 
    demo.configure_traits()
93
 
 
94
 
#--EOF