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

« back to all changes in this revision

Viewing changes to examples/demo/vertical_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
 
"""
2
 
Draw multiple side-by-side plots
3
 
 
4
 
Draws a static plot of bessel functions, oriented vertically, side-by-side.
5
 
 
6
 
You can experiment with using different orientations of containers or plots
7
 
by modifying lines 26 and 27.
8
 
"""
9
 
 
10
 
# Major library imports
11
 
from numpy import arange
12
 
from scipy.special import jn
13
 
 
14
 
from chaco.example_support import COLOR_PALETTE
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
 
from chaco.api import PlotLabel, VPlotContainer, HPlotContainer, \
21
 
    create_line_plot
22
 
 
23
 
# ======================================================================
24
 
# Change one or both of these to experiment with different orientations
25
 
# of the plot containers and the lines within each plot:
26
 
container_class = HPlotContainer # HPlotContainer or VPlotContainer
27
 
plot_orientation = 'v' # 'v' or 'h'
28
 
# ======================================================================
29
 
 
30
 
#===============================================================================
31
 
# # Create the Chaco plot.
32
 
#===============================================================================
33
 
def _create_plot_component():
34
 
    numpoints = 100
35
 
    low = -5
36
 
    high = 15.0
37
 
    x = arange(low, high, (high-low)/numpoints)
38
 
    container = container_class(resizable = "hv", bgcolor="lightgray",
39
 
                                fill_padding=True, padding = 10)
40
 
 
41
 
    # Plot some bessel functions
42
 
    value_range = None
43
 
    for i in range(10):
44
 
        y = jn(i, x)
45
 
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0,
46
 
                                orientation=plot_orientation)
47
 
        plot.origin_axis_visible = True
48
 
        plot.origin = "top left"
49
 
        plot.padding_left = 10
50
 
        plot.padding_right = 10
51
 
        plot.border_visible = True
52
 
        plot.bgcolor = "white"
53
 
        if value_range is None:
54
 
            value_range = plot.value_mapper.range
55
 
        else:
56
 
            plot.value_range = value_range
57
 
            value_range.add(plot.value)
58
 
        if i%2 == 1:
59
 
            plot.line_style = "dash"
60
 
        container.add(plot)
61
 
 
62
 
    container.padding_top = 50
63
 
    container.overlays.append(PlotLabel("Bessel Functions in a Strip Plot",
64
 
                                        component=container,
65
 
                                        font = "swiss 16",
66
 
                                        overlay_position = "top"))
67
 
 
68
 
    return container
69
 
 
70
 
#===============================================================================
71
 
# Attributes to use for the plot view.
72
 
size=(800,600)
73
 
title="Vertical Line Plot"
74
 
 
75
 
#===============================================================================
76
 
# # Demo class that is used by the demo.py application.
77
 
#===============================================================================
78
 
class Demo(HasTraits):
79
 
    plot = Instance(Component)
80
 
 
81
 
    traits_view = View(
82
 
                    Group(
83
 
                        Item('plot', editor=ComponentEditor(size=size),
84
 
                             show_label=False),
85
 
                        orientation = "vertical"),
86
 
                    resizable=True, title=title,
87
 
                    width=size[0], height=size[1]
88
 
                    )
89
 
 
90
 
    def _plot_default(self):
91
 
         return _create_plot_component()
92
 
 
93
 
demo = Demo()
94
 
 
95
 
if __name__ == "__main__":
96
 
    demo.configure_traits()