2
Demonstrates making a scatterplot with custom markers.
3
Interactions are the same as in scatter.py.
6
# Major library imports
7
from numpy import arange, sort
8
from numpy.random import random
10
from enthought.enable.example_support import DemoFrame, demo_main
12
# Enthought library imports
13
from enthought.enable.api import Component, ComponentEditor, Window
14
from enthought.enable.compiled_path import CompiledPath
15
from enthought.traits.api import HasTraits, Instance
16
from enthought.traits.ui.api import Item, Group, View
19
from enthought.chaco.api import ArrayPlotData, Plot
20
from enthought.chaco.tools.api import PanTool, ZoomTool
23
def make_custom_marker():
32
#===============================================================================
33
# # Create the Chaco plot.
34
#===============================================================================
35
def _create_plot_component():
39
x = sort(random(numpts))
42
# create a custom marker
43
marker = make_custom_marker()
45
# Create a plot data obect and give it this data
47
pd.set_data("index", x)
48
pd.set_data("value", y)
52
plot.plot(("index", "value"),
56
index_sort="ascending",
61
# Tweak some of the plot properties
62
plot.title = "Scatter plot with custom markers"
66
# Attach some tools to the plot
67
plot.tools.append(PanTool(plot, constrain_key="shift"))
68
zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
69
plot.overlays.append(zoom)
73
#===============================================================================
74
# Attributes to use for the plot view.
76
title = "Scatter plot w/ custom markers"
79
#===============================================================================
80
# # Demo class that is used by the demo.py application.
81
#===============================================================================
82
class Demo(HasTraits):
83
plot = Instance(Component)
87
Item('plot', editor=ComponentEditor(size=size,
90
orientation = "vertical"),
91
resizable=True, title=title
94
def _plot_default(self):
95
return _create_plot_component()
99
#===============================================================================
100
# Stand-alone frame to display the plot.
101
#===============================================================================
102
class PlotFrame(DemoFrame):
104
def _create_window(self):
105
# Return a window containing our plots
106
return Window(self, -1, component=_create_plot_component(),
109
if __name__ == "__main__":
110
demo_main(PlotFrame, size=size, title=title)
b'\\ No newline at end of file'