2
Draws a vector or "quiver" plot of a set of random points.
3
- Left-drag pans the plot.
4
- Mousewheel up and down zooms the plot in and out.
5
- Pressing "z" brings up the Zoom Box, and you can click-drag a rectangular
6
region to zoom. If you use a sequence of zoom boxes, pressing alt-left-arrow
7
and alt-right-arrow moves you forwards and backwards through the "zoom
11
# Major library imports
12
from numpy import array, sort
13
from numpy.random import random
15
# Enthought library imports
16
from enable.api import Component, ComponentEditor
17
from traits.api import HasTraits, Instance, Int
18
from traitsui.api import Item, View
21
from chaco.api import ArrayDataSource, MultiArrayDataSource, DataRange1D, \
22
LinearMapper, QuiverPlot, OverlayPlotContainer, add_default_grids, \
24
from chaco.tools.api import PanTool, ZoomTool
27
class PlotExample(HasTraits):
28
plot = Instance(Component)
32
traits_view = View(Item('plot', editor=ComponentEditor(), show_label=False),
33
width=600, height=600)
35
def _plot_default(self):
36
# Create starting points for the vectors.
38
x = sort(random(numpts))
42
vectorlen = self.vectorlen
43
vectors = array((random(numpts)*vectorlen, random(numpts)*vectorlen)).T
45
# Create an array data sources to plot all vectors at once
46
xs = ArrayDataSource(x, sort_order='ascending')
47
ys = ArrayDataSource(y)
48
vector_ds = MultiArrayDataSource(vectors)
51
xrange = DataRange1D()
53
yrange = DataRange1D()
56
quiverplot = QuiverPlot(index = xs, value = ys,
58
index_mapper = LinearMapper(range=xrange),
59
value_mapper = LinearMapper(range=yrange),
62
add_default_axes(quiverplot)
63
add_default_grids(quiverplot)
65
# Attach some tools to the plot
66
quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
67
zoom = ZoomTool(quiverplot)
68
quiverplot.overlays.append(zoom)
70
container = OverlayPlotContainer(quiverplot, padding=50)
77
if __name__ == "__main__":
78
demo.configure_traits()