forked from plotly/plotly.py
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.py
55 lines (50 loc) · 1.69 KB
/
tools.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
"""
Tools for matplotlib plot exporting
"""
defipynb_vega_init():
"""Initialize the IPython notebook display elements
This function borrows heavily from the excellent vincent package:
http://github.com/wrobstory/vincent
"""
try:
fromIPython.core.displayimportdisplay, HTML
exceptImportError:
print("IPython Notebook could not be loaded.")
require_js="""
if (window['d3'] === undefined) {{
require.config({{ paths: {{d3: "http://d3js.org/d3.v3.min"}} }});
require(["d3"], function(d3) {{
window.d3 = d3;
{0}
}});
}};
if (window['topojson'] === undefined) {{
require.config(
{{ paths: {{topojson: "http://d3js.org/topojson.v1.min"}} }}
);
require(["topojson"], function(topojson) {{
window.topojson = topojson;
}});
}};
"""
d3_geo_projection_js_url="http://d3js.org/d3.geo.projection.v0.min.js"
d3_layout_cloud_js_url="http://wrobstory.github.io/d3-cloud/""d3.layout.cloud.js"
topojson_js_url="http://d3js.org/topojson.v1.min.js"
vega_js_url="http://trifacta.github.com/vega/vega.js"
dep_libs="""$.getScript("%s", function() {
$.getScript("%s", function() {
$.getScript("%s", function() {
$.getScript("%s", function() {
$([IPython.events]).trigger("vega_loaded.vincent");
})
})
})
});"""% (
d3_geo_projection_js_url,
d3_layout_cloud_js_url,
topojson_js_url,
vega_js_url,
)
load_js=require_js.format(dep_libs)
html="<script>"+load_js+"</script>"
display(HTML(html))