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

« back to all changes in this revision

Viewing changes to examples/demo/basic/grid_container.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 resize restrictions
3
 
 
4
 
The ability of Plots to resize, when their container resizes, can be explicitly
5
 
restricted in either direction. This can place *implicit* restrictions on
6
 
other plots in the grid.
7
 
 
8
 
In this example, the upper left plot is explicitly restricted from resizing 
9
 
horizontally. The bottom center plot is explicitly restricted from resizing 
10
 
at all.
11
 
 
12
 
The resulting implicit restrictions on the other 4 plots are generally
13
 
intuitive, except that when the window gets too small to respect all of the
14
 
restrictions, the results are OS and GUI-backend-dependent, not easily 
15
 
predictable.
16
 
 
17
 
"""
18
 
 
19
 
# Major library imports
20
 
from numpy import linspace
21
 
from scipy.special import jn
22
 
 
23
 
from chaco.example_support import COLOR_PALETTE
24
 
 
25
 
# Enthought library imports
26
 
from enable.api import Component, ComponentEditor
27
 
from traits.api import HasTraits, Instance
28
 
from traitsui.api import Item, Group, View
29
 
 
30
 
# Chaco imports
31
 
from chaco.api import ArrayPlotData, GridContainer, Plot, PlotLabel
32
 
from chaco.tools.api import PanTool, ZoomTool
33
 
 
34
 
 
35
 
 
36
 
#===============================================================================
37
 
# # Create the Chaco plot.
38
 
#===============================================================================
39
 
def _create_plot_component():
40
 
    # Create a GridContainer to hold all of our plots: 2 rows, 3 columns:
41
 
    container = GridContainer(padding=40, fill_padding=True,
42
 
                              bgcolor="lightgray", use_backbuffer=True,
43
 
                              shape=(2,3), spacing=(20,20))
44
 
 
45
 
    # Create the initial series of data
46
 
    x = linspace(-5, 15.0, 100)
47
 
    pd = ArrayPlotData(index = x)
48
 
 
49
 
    # Plot some bessel functions and add the plots to our container
50
 
    for i in range(6):
51
 
        pd.set_data("y" + str(i), jn(i,x))
52
 
        plot = Plot(pd)
53
 
        plot.plot(("index", "y" + str(i)),
54
 
                  color=tuple(COLOR_PALETTE[i]), line_width=2.0,
55
 
                  bgcolor = "white", border_visible=True)
56
 
 
57
 
        # Tweak some of the plot properties
58
 
        plot.border_width = 1
59
 
        plot.padding = 0
60
 
        plot.padding_top = 30
61
 
 
62
 
        # Attach some tools to the plot
63
 
        plot.tools.append(PanTool(plot))
64
 
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
65
 
        plot.overlays.append(zoom)
66
 
 
67
 
        # Add to the grid container (
68
 
        container.add(plot)
69
 
 
70
 
    # Set the upper-left plot to only be resizable vertically, and to have a
71
 
    # fixed horizontal width. This also constrains the width of the first column.
72
 
    ul_plot = container.components[0]
73
 
    ul_plot.set(resizable="v", width=200)
74
 
    ul_plot.overlays.append(PlotLabel("Not horizontally resizable",
75
 
                                      component=ul_plot))
76
 
 
77
 
    # Set the bottom center plot to have a fixed width and height.
78
 
    # This also constrains the height of the bottom row and the width of
79
 
    # the middle column.
80
 
    cplot = container.components[4]
81
 
    cplot.set(resizable="", bounds=[400,400])
82
 
    cplot.overlays.append(PlotLabel("Not resizable", component=cplot))
83
 
 
84
 
    container.padding_top = 50
85
 
    container.overlays.append(
86
 
        PlotLabel('Resize the window - some plots resize, others cannot '
87
 
                  '(see source code)',
88
 
                  component=container,
89
 
                  font = "swiss 16",
90
 
                  overlay_position = "top"))
91
 
        
92
 
    return container
93
 
 
94
 
#===============================================================================
95
 
# Attributes to use for the plot view.
96
 
size=(1000,800)
97
 
title="Resizable Grid Container"
98
 
 
99
 
#===============================================================================
100
 
# # Demo class that is used by the demo.py application.
101
 
#===============================================================================
102
 
class Demo(HasTraits):
103
 
    plot = Instance(Component)
104
 
 
105
 
    traits_view = \
106
 
        View(
107
 
            Group(
108
 
                Item('plot', editor=ComponentEditor(size=size),
109
 
                        show_label=False),
110
 
                orientation = "vertical"
111
 
                ),
112
 
            resizable=True, title=title )
113
 
 
114
 
    def _plot_default(self):
115
 
         return _create_plot_component()
116
 
 
117
 
demo = Demo()
118
 
 
119
 
if __name__ == "__main__":
120
 
    demo.configure_traits()