-
Notifications
You must be signed in to change notification settings - Fork 100
/
bigdata.py
111 lines (88 loc) · 3.54 KB
/
bigdata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Demonstrates chaco performance with large datasets.
There are 10 plots with 100,000 points each. Right-click and drag to
create a range selection region. The region can be moved around and
resized (drag the edges). These interactions are very fast because
of the backbuffering built into chaco.
Zooming with the mousewheel and the zoombox (as described in simple_line.py)
is also available, but panning is not.
"""
# Major library imports
from scipy.special import jn
from numpy import arange
from chaco.example_support import COLOR_PALETTE
# Enthought library imports
from enable.api import Component, ComponentEditor
from traits.api import Bool, HasTraits, Instance
from traitsui.api import Group, Item, UItem, View
# Chaco imports
from chaco.api import OverlayPlotContainer, create_line_plot, add_default_axes, \
add_default_grids
from chaco.tools.api import RangeSelection, RangeSelectionOverlay, ZoomTool
#===============================================================================
# # Create the Chaco plot.
#===============================================================================
# Do the plots use downsampling?
use_downsampling = True
def _create_plot_component(use_downsampling=True):
container = OverlayPlotContainer(padding=40, bgcolor="lightgray",
use_backbuffer = True,
border_visible = True,
fill_padding = True)
numpoints = 100000
low = -5
high = 15.0
x = arange(low, high+0.001, (high-low)/numpoints)
# Plot some bessel functionsless ../en
value_mapper = None
index_mapper = None
for i in range(10):
y = jn(i, x)
plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
plot.use_downsampling = use_downsampling
if value_mapper is None:
index_mapper = plot.index_mapper
value_mapper = plot.value_mapper
add_default_grids(plot)
add_default_axes(plot)
else:
plot.value_mapper = value_mapper
value_mapper.range.add(plot.value)
plot.index_mapper = index_mapper
index_mapper.range.add(plot.index)
if i%2 == 1:
plot.line_style = "dash"
plot.bgcolor = "white"
container.add(plot)
selection_overlay = RangeSelectionOverlay(component = plot)
plot.tools.append(RangeSelection(plot))
zoom = ZoomTool(plot, tool_mode="box", always_on=False)
plot.overlays.append(selection_overlay)
plot.overlays.append(zoom)
return container
#===============================================================================
# Attributes to use for the plot view.
size = (600, 500)
title = "Million Point Plot"
#===============================================================================
# # Demo class that is used by the demo.py application.
#===============================================================================
class Demo(HasTraits):
plot = Instance(Component)
use_downsampling = Bool(True)
traits_view = View(
UItem('plot', editor=ComponentEditor()),
Group(Item('use_downsampling')),
width=size[0],
height=size[1],
resizable=True,
title=title
)
def _plot_default(self):
return _create_plot_component(self.use_downsampling)
def _use_downsampling_changed(self):
self.plot = _create_plot_component(self.use_downsampling)
demo = Demo()
if __name__ == "__main__":
demo.configure_traits()
#--EOF---