JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
475 stars 87 forks source link

Need `%matplotlib inline` twice when running via Python #472

Closed marius311 closed 4 years ago

marius311 commented 4 years ago

I wasn't sure whether to file here or in pyjulia, please feel free to transfer if this was the wrong choice.

Basically, from a fresh Python Jupyter kernel if I execute the following (each line in a separate cell):

%matplotlib inline
from julia.PyPlot import plot
plot([1,2,3])

then no inline plot is shown. I have to execute %matplotlib inline one more time before inline plots start showing. This does not happen if I replace from julia.PyPlot import plot with from matplotlib.pyplot import plot, not does it happen when plotting from a Julia kernel.

I have Julia 1.4, pyjulia 0.5.0, matplotlib 3.1.1, IJulia v1.21.1, PyPlot v2.8.2.

I found these Issues which seem could be related:

https://github.com/jupyter/notebook/issues/3691 https://github.com/ipython/ipython/pull/11916

If you're wondering why I'm not calling Python plot directly, its because Julia's version of plot can be (and is, in my case) specialized on the argument types. Interactively its no big deal to run it twice, but this is happening in some automatic documentation generation, where its slightly ugly to have the %matplotlib magic in there twice to make this work.

marius311 commented 4 years ago

Actually, looks like just flipping the order solves it:

from julia.PyPlot import plot
%matplotlib inline
plot([1,2,3])

Given this is totally satisfactory for me and this is otherwise probably such an edge case, I'm just going to close this issue, unless anyone else feels strongly it needs to be fixed.