JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 355 forks source link

[FR] mpld3 pyplot figures rendering #2764

Open isentropic opened 4 years ago

isentropic commented 4 years ago

In short, mpld3 is a javascript pyplot rendering backend. https://mpld3.github.io/quickstart.html It renders zoomable, panable plots with optional plugins. More examples here https://mpld3.github.io/notebooks/mpld3_demo.html Minimal example on what it is:

using Plots; pyplot()
using PyCall
p = plot(1:5)
mpld3 = pyimport("mpld3")
mpld3.display(p.o)  # if in not in jupyter notebook use: mpld3.show(p.o)

Why: Interactive (jupyter) plots are always desirable when exploring the data.

How can this be accomplished:

  1. Have a minimal mpld3 backend, similar to plotlyjs
  2. Let pyplot backend have an optional mpld3 flag
  3. Attempt importing mpld3, upon failure fallback to default pyplot rendering

My order of preference is definitely 2, 1, 3

Pros:

  1. Minimal code needs to written
  2. More consistent interactive backend. Plotly suffers from some unfixable issues like legends per subplots, colorbars,
  3. Should be persistent unlike plotly that requires careful jupyter setup.

Cons:

  1. Javascript hinders performance when datasets are huge (should not really be used in this case)
  2. Some maplotlib features are missing from mpld3 https://github.com/mpld3/mpld3/wiki#mpld3-missing-features
BeastyBlacksmith commented 4 years ago

If this is just about rendering pyplot objects differently in jupyter notebooks, I am definitely for option 2. If jupyter has its own MIME type, we could just add a show method for that?

isentropic commented 4 years ago

If this is just about rendering pyplot objects differently in jupyter notebooks, I am definitely for option 2.

It could be about rendering them from repl too. It's more like ORCA, WebIO, electron stack for plotly()

Having a separate backend mpld3 is more versatile, as users can switch around easily, but that would make it confusing like plotly/plotlyjs. Because technically it is not a separate backend.

You could really try and see what it is by checking the example I put up above

BeastyBlacksmith commented 4 years ago

So it is a general html renderer for matplotlib. And if we use that in the html-show method, you should get interactive Plots in jupyter as well as the juno-plot pane for example.

isentropic commented 4 years ago

You are right, this is javascript html renderer of pyplot figures