PyPlot doesn't do anything

Hello, I’m very new to Julia, I’m exploring it as an alternative to Matlab.

I’m using Windows 10 professional. I sucessfully installed the Packages PyCall, Plots and PyPlot. When I try to make a plot using the pyplots backend from the REPL, it accepts the command, and it looks like it starts working, but nothing happens. I run for example the following code.

using Plots
pyplot()
x=1:10; y=rand(10);
plot(x,y)

Then it stops. The cursor is blinking in the next line and no new line with Julia> in the beginning appears. Also it does not accept any new inputs.

I have a version of Python installed on my computer and I think I managed to add matplotlib to it.

I’d be glad if someone could make a suggestion what I might be doing wrong. Thanks.

You’re not doing anything wrong - there must be an error in your setup. It’s possible it has to do with the PyPlot install - an easy way to narrow that down would be to install a different backend, e.g. Pkg.add("GR"), then run the same code as above, replacing pyplot() with gr().

1 Like

What happens if you try running PyPlot directly?

using PyPlot
x = linspace(0,2*pi,1000); y = sin(3*x + 4*cos(2*x));
plot(x, y, color="red", linewidth=2.0, linestyle="--")
2 Likes

Thanks for the answer. If I do what you suggest, then I get a plot. How would I “fix” my PyPlot install?

I found on the internet that I should try

`ENV["PYTHON"]=""
Pkg.build("PyPlot")`

But still I have the same issue. Also I tried to set ENV["PYTHON"] to that path of a Python version that I installed on my computer, and that has matplotlib installed. Then when I try to build the package, I get a message that no global Python version was found.

It gives the same issue. Nothing happens.

It works now. I tried again setting the path to a Python version I installed and I built all the packages again. I guess it was just a typo in the path the first times. Thanks for your help.

1 Like

A (more) friendly error message could be added to PyCall.jl in case of that error saying “no Python installed at {your path}”?

PyCall is just an implementation detail to get PyPlot to work (and even many use Plots, not PyPlot directly…) so some newbies might easily miss those details.