Pluto.jl: Support for PyPlot & Plots.jl (GR, plotly) & PlotlyJS

Created on 3 Jun 2020  路  11Comments  路  Source: fonsp/Pluto.jl

Hi,

the README.md show pictures with graphics (referring to https://github.com/vdplasthijs/julia_sir ).

But the only graphics library I get running is UnicodePlots. Without color :-)

Well, I love UnicodePlots, but here I hoped for something more shiny.

I tried Plotly and PlotlyJS, both give me a blank canvas.

So,

  1. What library should I use (the Plots default, as I understand, is GR - makes no sense here)?
  2. Do you have an example using the current version of Pluto v0.9.2?

Thank you!

Kind greetings, z.

(PS.: Using

  • Julia 1.4.0 on Windows 10
  • Chrome browser)

PPS: Same with 0.9.3

Most helpful comment

Sorry to resurrect this... but just to let people know that PyPlot too works perfectly. From this issue I was under the impression it was not.

Great job! I will most likely switch to Pluto for my next semester computational lab at Politecnico di Torino. PyPlot integration was a bit of a prerequisite to me...

image

All 11 comments

Plots.jl with the GR backend works, and it is fast enough for interactivity! I know that standalone PyPlot doesn't work straight away (the plot function does not return an object that can be rendered - I think that it wants to hook into Jupyter's internals). Plotly used to work (as backend for the Plots.jl package), but it looks like I broke it again :)

It would be great if we could go through all plots packages and figure out if they work, and if not, what the workaround would be. Let's make that the topic of this issue!

I will start with Plotly!

More Info, from the Chrome DevTools

Couldn't execute script:
renderOutput @ editor.js:250
updateLocalCellOutput @ editor.js:321
onUpdate @ editor.js:552
(anonymous) @ PlutoConnection.js:101
Promise.then (async)
handleMessage @ PlutoConnection.js:83
psocket.onmessage @ PlutoConnection.js:114
editor.js:251 ReferenceError: Plotly is not defined
at HTMLDivElement.eval (eval at (editor.js:243), :5:5)
at editor.js:243
at Array.map ()
at renderOutput (editor.js:232)
at updateLocalCellOutput (editor.js:321)
at PlutoConnection.onUpdate (editor.js:552)
at PlutoConnection.js:101

GR should work??

Okay, so I have to fix my GR first. I assumed that GR always opens a new window, i.e. outside the browser.

Whistles ... Never assume!

Thank you! I'll keep you informed :-)

GR works. Thank you!

Yay!

For anyone who stumbles on this issue:

image

Sorry to resurrect this... but just to let people know that PyPlot too works perfectly. From this issue I was under the impression it was not.

Great job! I will most likely switch to Pluto for my next semester computational lab at Politecnico di Torino. PyPlot integration was a bit of a prerequisite to me...

image

Thanks so much! I changed the title because github search is not super smart

PyPlot's API is based on _side effects_, which can make it confusing to use inside Pluto. For example, if you forget gcf(), but you use it in a second cell, then the first cell will have no plot, and the second cell will have two plots on top of eachother.

To make things a little easier, you can write in one cell:

function with_pyplot(f::Function)
    f()
    fig = gcf()
    close(fig)
    return fig
end

you can then use it in other cells with:

with_pyplot() do
    title(...)
    plot(...)
    # etc
end

I'm not sure what close("all") does, but maybe you can add it inside the with_pyplot function

Thanks! For a function that generates multiple plots, I had to use this:

function with_pyplot(f::Function)
    f()
    figs = [figure(num) for num in get_fignums()]
    close("all")
    return figs
end
Was this page helpful?
0 / 5 - 0 ratings

Related issues

aramirezreyes picture aramirezreyes  路  3Comments

jarvist picture jarvist  路  6Comments

fonsp picture fonsp  路  5Comments

kapple19 picture kapple19  路  5Comments

fonsp picture fonsp  路  5Comments