How to have the same behaviour such as python's plt.plot()?

Hello to everyone, I’m new to Julia language and I come from Python. I’ve understood how to plot correctly, by using the display() function, but the plot, once created, immediately disappear. How can I have a blocking behavior?

Hi Vicodin96! Welcome to the Julia community.

I understand you have a script with your plotting commads and you run it like julia myscript.jl from the terminal, is that correct?

Then the window will dissapear when then process finishes, unless you launch it like julia -i myscript.jl, which will open the REPL at the end.

One thing to note, though, is that Julia is not very well suited for script-based plotting in that way, beacuse the time before everything gets compiled and shown will be terribly long.

We usually keep a REPL open. From there you can call your script via `julia> include(“myscript.jl”).

3 Likes

Hi @Argel_Ramirez_Reyes ! Yes, I have my script but I run it with Python’s IDE: PyCharm. It has an extension for Julia Programming Language. The window disappear after the expression is evaluated. What IDE do you suggest? Which is the correct way to plot in Julia?

Most people use VSCode Julia extension or Juno (atom plugin), with development moving toward the first one.
You then just run the single plot(somehting) function and the plot appears on a dedicated plot pane…

Are you by chance saving the plot to a figure in the same script? For some reason when you do that the plot pane goes away.

(If that, something that could be improved IMHO)

Yep, I know that people use Juno or VS Code but I don’t want 2 IDEs, no I’m not saving the plot to a figure. The code that I’m running is the following:

using Statistics
using Plots
using CSV
using DataFrames
using DataConvenience
using Statistics
train_data = CSV.read("./src/titanic/train.csv",DataFrame)
println(describe(train_data))
numerical_columns = ["Age", "SibSp", "Parch", "Fare"]
cat_columns = ["Survived", "Pclass", "Sex", "Ticket", "Cabin", "Embarked"]
df_num = train_data[:, numerical_columns]
df_cat = train_data[:, cat_columns]
for name in numerical_columns
println(name)
display(histogram(collect(skipmissing(df_num[:, name])),title = name,label=name))
readline() #to stop the execution and see the plot
end

I’m just translating the code proposed by this guy with the Titanic DataSet, Here the code in python.

I think a better MWE would be:

using Plots
plot(rand(10))

when you run this, does the same thing happen? What if you run this in the standard Julia REPL?

hi @nilshg, if I run it in Pycharm (adding display() function in this way: display(plot(rand(10)))), the plot disappears while with the standard REPL it doesn’t.

Good, so we have at least identified PyCharm as the culprit - do you have the same problem with other Plots backends, or indeed other plotting libraries (e.g. Gadfly)?

I’m not a PyCharm user myself so unfortunately can’t reproduce this, but hopefully someone else will come along!

@nilshg I’ve tried pyplot as backend and the plot still disappear, while with plotly() it opens a window in my browser to show the image :confused:

Yes that’s expected with Plotly. What about using a non-Plots library, such as Gadfly?

With Gadfly it also opens a tab in my browser, but the image is white