-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiflot.py
64 lines (49 loc) · 2.2 KB
/
iflot.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
"""
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Stdlib imports
import string
import json
import IPython.core.display
#-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
class Plot():
'''
'''
def create_plot_placeholder( self, name, **kargs ):
src = """
<div id="%(n)s" style="width:600px;height:300px;"/>
"""%{'n':name}
IPython.core.display.display_html(IPython.core.display.HTML(data=src))
#print (src)
def plot( self, data, options, name = None):
"""
data = [(x1,y1,options1),(x2,y2,options2),...]
"""
if name is None:
name = str(self.nextName)
self.nextName += 1
self.create_plot_placeholder(name)
src = ''
encoder = json.JSONEncoder()
src += 'var plot%(n)s = $.plot($("#%(n)s"), ['%{'n':name}
for sernum,ser in enumerate(data):
src += "{data : %s , %s },\n"%(encoder.encode(zip(ser[0],ser[1])), encoder.encode(ser[2])[1:-1])
src += '], %s);'%encoder.encode(options)
IPython.core.display.display_javascript(IPython.core.display.Javascript(data=src,
lib=["http://cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.min.js",
"http://cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.navigate.min.js",
"http://cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.selection.min.js",
"http://cdnjs.cloudflare.com/ajax/libs/flot/0.7/jquery.flot.pie.min.js",
]))
#print (src)