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

« back to all changes in this revision

Viewing changes to examples/demo/basic/nans_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
 
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
9
 
   history".
10
 
"""
11
 
 
12
 
# Major library imports
13
 
from numpy import linspace, nan
14
 
from scipy.special import jn
15
 
 
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
20
 
 
21
 
# Chaco imports
22
 
from chaco.api import ArrayPlotData, Plot
23
 
from chaco.tools.api import PanTool, ZoomTool
24
 
 
25
 
#===============================================================================
26
 
# # Create the Chaco plot.
27
 
#===============================================================================
28
 
def _create_plot_component():
29
 
 
30
 
    # Create some x-y data series (with NaNs) to plot
31
 
    x = linspace(-5.0, 15.0, 500)
32
 
    x[75:125] = nan
33
 
    x[200:250] = nan
34
 
    x[300:330] = nan
35
 
    pd = ArrayPlotData(index = x)
36
 
    pd.set_data("value1", jn(0, x))
37
 
    pd.set_data("value2", jn(1, x))
38
 
 
39
 
    # Create some line and scatter plots of the data
40
 
    plot = Plot(pd)
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")
44
 
 
45
 
    # Tweak some of the plot properties
46
 
    plot.title = "Plots with NaNs"
47
 
    plot.padding = 50
48
 
    plot.legend.visible = True
49
 
 
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)
54
 
 
55
 
    return plot
56
 
 
57
 
#===============================================================================
58
 
# Attributes to use for the plot view.
59
 
size = (800, 700)
60
 
title = "Nan Test"
61
 
 
62
 
#===============================================================================
63
 
# # Demo class that is used by the demo.py application.
64
 
#===============================================================================
65
 
class Demo(HasTraits):
66
 
    plot = Instance(Component)
67
 
 
68
 
    traits_view = View(
69
 
                    Group(
70
 
                        Item('plot', editor=ComponentEditor(size=size),
71
 
                             show_label=False),
72
 
                        orientation = "vertical"),
73
 
                    resizable=True, title=title
74
 
                    )
75
 
 
76
 
    def _plot_default(self):
77
 
         return _create_plot_component()
78
 
 
79
 
demo = Demo()
80
 
 
81
 
if __name__ == "__main__":
82
 
    demo.configure_traits()
83
 
 
84
 
#--EOF---