PyPlot does not show me any plot

I installed Julia 1.9.3 on my windows 11 pc and add the package PyPlot. Then, going in VS code the Julia version is immediately recognize (so okay). Whenever I write using PyPlot all works well, but when I try to make a very simple plot, for example plot(rand(5)) including gcf() the code run and run without stopping and show me the plot. How can I fix the problem? Writing instead the same lines of code in the REPL it seems to appear the plot, but then all close automatically.

Thanks in advance for all suggestions!

Welcome to the forum.
If you can’t find out the cause of the problem, you could also try PythonPlot.jl instead. It might be more reliable and it uses the same plotting library.

I considered that solution, as well as also Plots, and both work. The problem is that I have to run codes that are written with PyPlot and just replace the name of the package does not work since seems that they have different commands. On my old computer all goes well, but when I installed on my new pc the problem start.

Code for PyPlot should be mostly compatible with PythonPlot, with some small differences described here:

I prefer to stick to PyPlot.jl, and it works fine for me (using Julia 1.10.2).

If there is a problem with PyPlot.jl, often the following command helps:

using Pkg"PyCall")

Thanks a lot, this now work, to be honest I think that it’s not the better solution, but since it works it’s fine :grin:. Thanks!!

Thanks for the suggestion, but it seems that nothing happens, I attach the output on the REPL

julia> using Pkg
Building Conda ─→ C:\Users\Andrea\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\51cab8e982c5b598eea9c8ceaced4b58d9dd37c9\build.log
Building PyCall → C:\Users\Andrea\.julia\scratchspaces\44cfe95a-1eb2-52ea-b672-e2afdf69b78f\9816a3826b0ebf49ab4926e2b18842ad8b5c8f04\build.log

After doing this when I try to make a plot with PyPlot all is as before.

For PyPlot, you likely need to (re)configure to use a particular Python. PythonPlot creates a new environment for each Julia environment.

PyPlot uses Python/matplotlib so you need to have those installed. Once you have that, you can do

using PyPlot
display(gcf())         #to force VScode to show the plot. may not be needed

Not entirely true. If you do:


and then install PyPlot a version on Python + Matplotlib gets installed just for Julia projects…

1 Like