# Plotting fails silently?

**URL:** <https://discourse.julialang.org/t/plotting-fails-silently/49406>\
**Category:** New to Julia\
**Tags:** question, plotting\
**Created:** [November 1, 2020, 10:20am UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406 "2020-11-01T10:20:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 10:20am UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/1 "2020-11-01T10:20:21Z")

</div>

I have a fresh install of Julia(on Catalina), with `Plots` added via `Pkg`. Then I try to plot a simple line:

```julia
using Plots; println("imported")
x = 1:10; y = rand(10); # These are the plotting data
println("tryna plot"); plot(x, y); println("you see?")

```

Running this file via `julia try.jl` just prints out the two prints. (Although, it happily plots to GSKTerm from REPL).  
My question is, why does it fail silently? Shouldn’t Julia tell me that it didn’t find any backends to complete `plot(x,y)`? Is it a design choice(in which case, where can I read more about it)?

Why not end with a non-zero exit code at least?

Thank You  
Warm Regards

Edit: Of course above code will never display the plot, as `;` suppresses it. But my initial attempts were without the `;`, which was added for brevity. I shan’t fix the code above as it will take away from @Volker’s instructive comment.

---

<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:** [November 1, 2020, 10:51am UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/2 "2020-11-01T10:51:35Z")

</div>

It is not failing, the script exits and you do not have time to see the plot. Add a `savefig("plot.png")` and you will get the result in that file. Or else you need to pause the script, for example adding a `read` statement after plotting.

---

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 11:49am UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/3 "2020-11-01T11:49:02Z")

</div>

Thank you, saving the plot confirms that it is indeed plotting properly.

But, if I pause the script via `sleep(60)`, I still don’t see the output anywhere, in GSKTerm or any of the browsers.

---

<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:** [November 1, 2020, 12:25pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/4 "2020-11-01T12:25:58Z")

</div>

I cannot test that now, but perhaps adding `display()` will force the plot to show up.

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [November 1, 2020, 12:47pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/5 "2020-11-01T12:47:23Z")

</div>

Hi,

You can simply write it without `;`, if you write each command in a single line.

```julia
using Plots
println("imported")
x = 1:10 
y = rand(10) # These are the plotting data
println("tryna plot") 
plot(x, y) 
println("you see?")

```

I use `;` at the end of line just, if I would like to plot more things on the axis or to create a subplot and don´t want to see the interim plots, i.e.:

```julia
p1 = plot(x, y);
plot!(p1, x, 10*y)

```

or

```julia
p1 = plot(x, y);
p2 = plot(x, 10*y);
plot(p1,p2, layout=(2,1))

```

if you would like to write in a single line then you need the semicolon to separate the commands. In this case use `display()` or `gui()`.

---

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 12:58pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/6 "2020-11-01T12:58:16Z")

</div>

Indeed, it does show up in GKSTerm. So, what happens to the plot otherwise? It simply gets computed but not displayed huh?  
Shouldn’t it get displayed due to `plot(x,y)` anyway, as that line returns the plot, and, as mentioned [here](https://docs.juliaplots.org/latest/output/)

> **A Plot is only displayed when returned** (a semicolon will suppress the return)

Thank You so much for the clarifications.

---

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 1:10pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/7 "2020-11-01T13:10:00Z")

</div>

I appreciate your help, but I was using the semi-colons to cut down on the number of lines while also being able to ‘see’ whats going on. For example, the first `println` told me that `using Plots` takes an awful lot of time to happen(which still has me bewildered).

Also, in your code, what does `!` do?

> [@Volker](#):
>
> ```julia
> plot!(p1, x, 10*y)
> 
> ```

Docs [here](https://docs.julialang.org/en/v1/base/punctuation/) told me that

> function names that end with an exclamation mark modify one or more of their arguments by convention

But I still don’t grok `plot!`, which parameter is changed by `!`? and why?

My apologies for the barrage of questions.  
Thank You

---

<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:** [November 1, 2020, 1:17pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/8 "2020-11-01T13:17:10Z")

</div>

> [@Ayush\_Rawat](#):
>
> But I still don’t grok `plot!` , which parameter is changed by `!` ? and why?

The plot itself. You can add curves or change the plot properties using that.

```julia
plot()
plot!(rand(3),rand(3),label="first")
plot!(rand(3),rand(3),label="second")
plot!(xlabel="x",ylabel="y")
savefig("plot.pdf")

```

---

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 1:21pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/9 "2020-11-01T13:21:05Z")

</div>

**Whoa!** that’s amazing,  
This composability is so reminiscent of Mathematica.  
P.S. python doesn’t have something like this does it?

---

<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:** [November 1, 2020, 1:35pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/10 "2020-11-01T13:35:44Z")

</div>

Take a look at the examples of Plots. And I have this text with some ideas: [Tips to create beautiful, publication-quality plots in Julia - Nextjournal](https://nextjournal.com/leandromartinez98/tips-to-create-beautiful-publication-quality-plots-in-julia)

---

<div class="post-metadata">

**Author:** ![Ayush\_Rawat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ayush_rawat/32/18961_2.png) [@Ayush\_Rawat](https://discourse.julialang.org/u/Ayush_Rawat)\
**Post date:** [November 1, 2020, 1:44pm UTC](https://discourse.julialang.org/t/plotting-fails-silently/49406/11 "2020-11-01T13:44:04Z")

</div>

Lately I’ve been exploring plotting only, thank you again for resources.
