How to Fix Plot GUI/WIndow not showing again / Anymore?

I have a problem, probably due to plotting a lot of graphs. I can’t plot anymore. Either using pyplot() or gr() as backend the plot window / gui does not comes out, I try with working codes and the window never shown again, but on REPL the codes run.

What to do to fix the plotting GUI/window problem? (I suspect this is due to the plot of step function I tried tremendously yesterday [x + 1/2]

This is the problematic codes:

using Plots, LaTeXStrings, Plots.PlotMeasures
pyplot()

f(x) = floor(x + 1/2)
x = -5.5:1:4.5
y = f.(x)

plot(x[1:2], [y[1], y[1]], label=L"f(x) = \lfloor x + 1/2 \rfloor", legend=:bottomleft,legend_foreground_color=:white,
legend_font_color=:blue, color=:blue, showaxis=false, tickfontcolor=:white)

# axis
hline!((0,0), color=:black, label="")
vline!((0,0), color=:black, label="")

# Scale values
for i in x
	if i!= 0
		annotate!(i,-0.2, (i, 7))
	end
end

for i in y
	if i != 0
		annotate!(-.2, i, (i, 7))
	end
end

annotate!(-.2, -.2, ("0", 7))

# Plot function
for i in 2:length(x)-1
	plot!(x[i:i+1], [y[i], y[i]], label="", color=:blue, lw=2)
end

The codes run without error or warning but the GUI/window is not showing (attachment below):

Capture d’écran_2022-09-13_15-43-49

Yes you’re correct - there’s a limited number of plots you can do with Julia (I think it’s around 13,500), and once you reached that you need to re-install Julia on a different computer.

No just kidding you can plot as much as you want but you do need to understand that plots are only displayed if you’re evaluating an expression which returns a plot object. When you do

for i in something
    plot(i)
end

the return value is nothing, as that’s what all loops in Julia return. You need to either

  1. Create an explicit plot object p = plot() before the loop and then call it after; or
  2. Call current() if you want to display the current plot object (the last one plotted to)

This isn’t unique to plots btw, here’s how integers behave:

julia> 2
2

julia> for i ∈ 1:10
           2
       end

julia>
1 Like

ERROR: You have reached the maximum amount of plots allowed in the Julia Base version. Please purchase the LotsOfPlots expansion pack to be able to plot more.


(Also just a joke.)

For the original issue, two more options are:

  • add a show = true argument to your first plot call
  • call gui() at the end of the script