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

« back to all changes in this revision

Viewing changes to examples/demo/basic/grid_container_aspect_ratio.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
 
Grid containing plots with fixed aspect ratios
3
 
 
4
 
Each plot in this example has a specified aspect ratio which will not
5
 
change no matter how the window is resized.
6
 
"""
7
 
 
8
 
# Major library imports
9
 
from numpy import linspace
10
 
from scipy.special import jn
11
 
 
12
 
from chaco.example_support import COLOR_PALETTE
13
 
 
14
 
# Enthought library imports
15
 
from enable.api import Component, ComponentEditor
16
 
from traits.api import HasTraits, Instance
17
 
from traitsui.api import Item, Group, View
18
 
 
19
 
# Chaco imports
20
 
from chaco.api import ArrayPlotData, GridContainer, Plot
21
 
from chaco.tools.api import PanTool, ZoomTool
22
 
 
23
 
 
24
 
#===============================================================================
25
 
# # Create the Chaco plot.
26
 
#===============================================================================
27
 
def _create_plot_component():
28
 
    # Create a GridContainer to hold all of our plots
29
 
    container = GridContainer(padding=20, fill_padding=True,
30
 
                              bgcolor="lightgray", use_backbuffer=True,
31
 
                              shape=(3,3), spacing=(12,12))
32
 
 
33
 
    # Create the initial series of data
34
 
    x = linspace(-5, 15.0, 100)
35
 
    pd = ArrayPlotData(index = x)
36
 
 
37
 
    # Plot some bessel functions and add the plots to our container
38
 
    for i in range(9):
39
 
        pd.set_data("y" + str(i), jn(i,x))
40
 
        plot = Plot(pd)
41
 
        plot.plot(("index", "y" + str(i)),
42
 
                  color=tuple(COLOR_PALETTE[i]), line_width=2.0,
43
 
                  bgcolor = "white", border_visible=True)
44
 
 
45
 
        # Tweak some of the plot properties
46
 
        plot.border_width = 1
47
 
        plot.padding = 10
48
 
 
49
 
        # Set each plot's aspect ratio based on its position in the
50
 
        # 3x3 grid of plots.
51
 
        n,m = divmod(i, 3)
52
 
        plot.aspect_ratio = float(n+1) / (m+1)
53
 
 
54
 
        # Attach some tools to the plot
55
 
        plot.tools.append(PanTool(plot))
56
 
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
57
 
        plot.overlays.append(zoom)
58
 
 
59
 
        # Add to the grid container
60
 
        container.add(plot)
61
 
    return container
62
 
 
63
 
#===============================================================================
64
 
# Attributes to use for the plot view.
65
 
size=(1000,800)
66
 
title="Grid Container with Fixed Aspect ratios"
67
 
 
68
 
#===============================================================================
69
 
# # Demo class that is used by the demo.py application.
70
 
#===============================================================================
71
 
class Demo(HasTraits):
72
 
    plot = Instance(Component)
73
 
 
74
 
    traits_view = View(
75
 
                    Group(
76
 
                        Item('plot', editor=ComponentEditor(size=size),
77
 
                             show_label=False),
78
 
                        orientation = "vertical"),
79
 
                    resizable=True, title=title
80
 
                    )
81
 
    def _plot_default(self):
82
 
         return _create_plot_component()
83
 
 
84
 
demo = Demo()
85
 
 
86
 
if __name__ == "__main__":
87
 
    demo.configure_traits()