2
Grid containing plots with resize restrictions
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.
8
In this example, the upper left plot is explicitly restricted from resizing
9
horizontally. The bottom center plot is explicitly restricted from resizing
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
19
# Major library imports
20
from numpy import linspace
21
from scipy.special import jn
23
from chaco.example_support import COLOR_PALETTE
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
31
from chaco.api import ArrayPlotData, GridContainer, Plot, PlotLabel
32
from chaco.tools.api import PanTool, ZoomTool
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))
45
# Create the initial series of data
46
x = linspace(-5, 15.0, 100)
47
pd = ArrayPlotData(index = x)
49
# Plot some bessel functions and add the plots to our container
51
pd.set_data("y" + str(i), jn(i,x))
53
plot.plot(("index", "y" + str(i)),
54
color=tuple(COLOR_PALETTE[i]), line_width=2.0,
55
bgcolor = "white", border_visible=True)
57
# Tweak some of the plot properties
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)
67
# Add to the grid container (
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",
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
80
cplot = container.components[4]
81
cplot.set(resizable="", bounds=[400,400])
82
cplot.overlays.append(PlotLabel("Not resizable", component=cplot))
84
container.padding_top = 50
85
container.overlays.append(
86
PlotLabel('Resize the window - some plots resize, others cannot '
90
overlay_position = "top"))
94
#===============================================================================
95
# Attributes to use for the plot view.
97
title="Resizable Grid Container"
99
#===============================================================================
100
# # Demo class that is used by the demo.py application.
101
#===============================================================================
102
class Demo(HasTraits):
103
plot = Instance(Component)
108
Item('plot', editor=ComponentEditor(size=size),
110
orientation = "vertical"
112
resizable=True, title=title )
114
def _plot_default(self):
115
return _create_plot_component()
119
if __name__ == "__main__":
120
demo.configure_traits()