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

**URL:** https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801
**Category:** Visualization
**Tags:** plotting
**Created:** [May 25, 2021, 5:46pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801 "2021-05-25T17:46:24Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 25, 2021, 5:46pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/1 "2021-05-25T17:46:24Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)
#### Post date: [May 25, 2021, 6:57pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/2 "2021-05-25T18:57:11Z")

</div>

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”).

---

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 25, 2021, 8:26pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/3 "2021-05-25T20:26:24Z")

</div>

Hi @aramirezreyes ! 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?

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [May 26, 2021, 2:38pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/4 "2021-05-26T14:38:01Z")

</div>

Most people use [VSCode Julia extension](https://www.julia-vscode.org/) or [Juno](https://junolab.org/) (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…

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [May 26, 2021, 4:55pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/5 "2021-05-26T16:55:47Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 27, 2021, 8:20am UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/6 "2021-05-27T08:20:21Z")

</div>

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:

```julia
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](https://www.youtube.com/watch?v=I3FBJdiExcg), [Here the code in python](https://www.kaggle.com/kenjee/titanic-project-example).

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 27, 2021, 8:54am UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/7 "2021-05-27T08:54:28Z")

</div>

I think a better MWE would be:

```julia
using Plots
plot(rand(10))

```

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

---

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 27, 2021, 10:40am UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/8 "2021-05-27T10:40:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 27, 2021, 12:01pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/9 "2021-05-27T12:01:51Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 27, 2021, 2:56pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/10 "2021-05-27T14:56:44Z")

</div>

@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 😕

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [May 27, 2021, 4:42pm UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/11 "2021-05-27T16:42:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Vicodin96](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Vicodin96](https://discourse.julialang.org/u/Vicodin96)
#### Post date: [May 28, 2021, 8:52am UTC](https://discourse.julialang.org/t/how-to-have-the-same-behaviour-such-as-pythons-plt-plot/61801/12 "2021-05-28T08:52:18Z")

</div>

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