2
Grid containing plots with fixed aspect ratios
4
Each plot in this example has a specified aspect ratio which will not
5
change no matter how the window is resized.
8
# Major library imports
9
from numpy import linspace
10
from scipy.special import jn
12
from chaco.example_support import COLOR_PALETTE
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
20
from chaco.api import ArrayPlotData, GridContainer, Plot
21
from chaco.tools.api import PanTool, ZoomTool
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))
33
# Create the initial series of data
34
x = linspace(-5, 15.0, 100)
35
pd = ArrayPlotData(index = x)
37
# Plot some bessel functions and add the plots to our container
39
pd.set_data("y" + str(i), jn(i,x))
41
plot.plot(("index", "y" + str(i)),
42
color=tuple(COLOR_PALETTE[i]), line_width=2.0,
43
bgcolor = "white", border_visible=True)
45
# Tweak some of the plot properties
49
# Set each plot's aspect ratio based on its position in the
52
plot.aspect_ratio = float(n+1) / (m+1)
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)
59
# Add to the grid container
63
#===============================================================================
64
# Attributes to use for the plot view.
66
title="Grid Container with Fixed Aspect ratios"
68
#===============================================================================
69
# # Demo class that is used by the demo.py application.
70
#===============================================================================
71
class Demo(HasTraits):
72
plot = Instance(Component)
76
Item('plot', editor=ComponentEditor(size=size),
78
orientation = "vertical"),
79
resizable=True, title=title
81
def _plot_default(self):
82
return _create_plot_component()
86
if __name__ == "__main__":
87
demo.configure_traits()