~ubuntu-branches/ubuntu/oneiric/python-chaco/oneiric

« back to all changes in this revision

Viewing changes to examples/basic/scatter_custom_marker.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 20:38:02 UTC
  • mfrom: (7.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110708203802-5t32e0ldv441yh90
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Depend on python-traitsui (Closes: #633604)
  - Bump Standards-Version to 3.9.2
* Update debian/watch file
* Remove debian/patches/* -- no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Demonstrates making a scatterplot with custom markers.
3
 
Interactions are the same as in scatter.py.
4
 
"""
5
 
 
6
 
# Major library imports
7
 
from numpy import arange, sort
8
 
from numpy.random import random
9
 
 
10
 
from enthought.enable.example_support import DemoFrame, demo_main
11
 
 
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
17
 
 
18
 
# Chaco imports
19
 
from enthought.chaco.api import ArrayPlotData, Plot
20
 
from enthought.chaco.tools.api import PanTool, ZoomTool
21
 
 
22
 
 
23
 
def make_custom_marker():
24
 
    path = CompiledPath()
25
 
    path.move_to(-5,-5)
26
 
    path.line_to(5, 5)
27
 
    path.line_to(5, -5)
28
 
    path.line_to(-5, 5)
29
 
    path.line_to(-5, -5)
30
 
    return path
31
 
 
32
 
#===============================================================================
33
 
# # Create the Chaco plot.
34
 
#===============================================================================
35
 
def _create_plot_component():
36
 
    
37
 
    # Create some data
38
 
    numpts = 300
39
 
    x = sort(random(numpts))
40
 
    y = random(numpts)
41
 
 
42
 
    # create a custom marker
43
 
    marker = make_custom_marker()
44
 
 
45
 
    # Create a plot data obect and give it this data
46
 
    pd = ArrayPlotData()
47
 
    pd.set_data("index", x)
48
 
    pd.set_data("value", y)
49
 
 
50
 
    # Create the plot
51
 
    plot = Plot(pd)
52
 
    plot.plot(("index", "value"),
53
 
              type="scatter",
54
 
              marker="custom",
55
 
              custom_symbol=marker,
56
 
              index_sort="ascending",
57
 
              color="orange",
58
 
              marker_size=3,
59
 
              bgcolor="white")
60
 
 
61
 
    # Tweak some of the plot properties
62
 
    plot.title = "Scatter plot with custom markers"
63
 
    plot.line_width = 0.5
64
 
    plot.padding = 50
65
 
 
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)
70
 
 
71
 
    return plot
72
 
 
73
 
#===============================================================================
74
 
# Attributes to use for the plot view.
75
 
size = (650, 650)
76
 
title = "Scatter plot w/ custom markers"
77
 
bg_color="lightgray"
78
 
        
79
 
#===============================================================================
80
 
# # Demo class that is used by the demo.py application.
81
 
#===============================================================================
82
 
class Demo(HasTraits):
83
 
    plot = Instance(Component)
84
 
    
85
 
    traits_view = View(
86
 
                    Group(
87
 
                        Item('plot', editor=ComponentEditor(size=size,
88
 
                                                            bgcolor=bg_color), 
89
 
                             show_label=False),
90
 
                        orientation = "vertical"),
91
 
                    resizable=True, title=title
92
 
                    )
93
 
    
94
 
    def _plot_default(self):
95
 
         return _create_plot_component()
96
 
    
97
 
demo = Demo()
98
 
 
99
 
#===============================================================================
100
 
# Stand-alone frame to display the plot.
101
 
#===============================================================================
102
 
class PlotFrame(DemoFrame):
103
 
 
104
 
    def _create_window(self):
105
 
        # Return a window containing our plots
106
 
        return Window(self, -1, component=_create_plot_component(),
107
 
                      bg_color=bg_color)
108
 
    
109
 
if __name__ == "__main__":
110
 
    demo_main(PlotFrame, size=size, title=title)
111
 
 
112
 
#--EOF---
 
 
b'\\ No newline at end of file'