PyPlot.jl
PyPlot.jl copied to clipboard
mpld3 support
Not sure weather this belongs here or in IJulia, but is there any forthcoming support for http://mpld3.github.io?
I haven't tried MPLD3, but I don't see any particular reason why calling these functions now, via PyCall, wouldn't work already. Try it and see what happens.
i.e. try something like
using PyPlot
using PyCall
@pyimport mpld3
plot(rand(10))
mpld3.save_html()
Hopefully mpld3.show() will work, and perhaps even mpld3.display() will work to display it inline in the notebook; the latter depends precisely on how they did it, though (e.g. it sounds like mpld3.display() just returns an object with a repr_html method, in which case it should work in IJulia too).
save_html() needs a figure instance as input. i tried save_html(gcf()) but it didn't work because gcf() fails with
PyError (PyObject_Call) <class 'AssertionError'>
AssertionError()
File "/usr/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2169, in print_figure
bbox_inches = self.figure.get_tightbbox(renderer)
File "/usr/lib/python3.4/site-packages/matplotlib/figure.py", line 1565, in get_tightbbox
_bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
File "/usr/lib/python3.4/site-packages/matplotlib/transforms.py", line 714, in union
assert(len(bboxes))
in pyerr_check at /home/berceanu/.julia/v0.3/PyCall/src/exception.jl:58
in pycall at /home/berceanu/.julia/v0.3/PyCall/src/PyCall.jl:85
in fn at /home/berceanu/.julia/v0.3/PyCall/src/conversions.jl:181
in writemime at /home/berceanu/.julia/v0.3/PyPlot/src/PyPlot.jl:145
in base64 at base64.jl:125
in display_dict at /home/berceanu/.julia/v0.3/IJulia/src/execute_request.jl:34
Not sure what is going on there. Did you try mpld3.show() or mpld3.display()?
yup
mpld3.show() -> kernel becomes unresponsive
`mpld3.display()' gives
`PyError (PyObject_Call) <class 'AssertionError'>
AssertionError()
File "/usr/lib/python3.4/site-packages/matplotlib/backend_bases.py", line 2169, in print_figure
bbox_inches = self.figure.get_tightbbox(renderer)
File "/usr/lib/python3.4/site-packages/matplotlib/figure.py", line 1565, in get_tightbbox
_bbox = Bbox.union([b for b in bb if b.width != 0 or b.height != 0])
File "/usr/lib/python3.4/site-packages/matplotlib/transforms.py", line 714, in union
assert(len(bboxes))
in pyerr_check at /home/berceanu/.julia/v0.3/PyCall/src/exception.jl:58
in pycall at /home/berceanu/.julia/v0.3/PyCall/src/PyCall.jl:85
in fn at /home/berceanu/.julia/v0.3/PyCall/src/conversions.jl:181
in writemime at /home/berceanu/.julia/v0.3/PyPlot/src/PyPlot.jl:145
in base64 at base64.jl:125
in display_dict at /home/berceanu/.julia/v0.3/IJulia/src/execute_request.jl:34
in display at /home/berceanu/.julia/v0.3/IJulia/src/inline.jl:35
in display at multimedia.jl:149
in display at /home/berceanu/.julia/v0.3/IJulia/src/inline.jl:56
Was curious if this works now. The following did (a straight translation of http://mpld3.github.io/examples/scatter_tooltip.html). I couldn't get this brushing in this one to work though: http://mpld3.github.io/examples/linked_brush.html.
using PyPlot
using PyCall
@pyimport mpld3
pygui(true) # suppresses drawing in IJulia, but must be better way
fig, ax = subplots(subplot_kw={:axisbg=>"#EEEEEE"})
N = 100
scatter = ax[:scatter](randn(N),
randn(N),
c=rand(N),
s=1000 * rand(N),
alpha=0.3,
cmap=PyPlot.cm[:jet])
ax[:grid](color="white", linestyle="solid")
ax[:set_title]("Scatter Plot (with tooltips!)", size=20)
labels = ["point $i" for i in 1:N]
tooltip = mpld3.plugins[:PointLabelTooltip](scatter, labels=labels)
mpld3.plugins[:connect](gcf(), tooltip)
mpld3.display(gcf())