# Redraw in GKSTerm Asleep? (and Gray mysteries)

**URL:** <https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099>\
**Category:** Visualization\
**Created:** [September 17, 2018, 11:19pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099 "2018-09-17T23:19:47Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 17, 2018, 11:19pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/1 "2018-09-17T23:19:47Z")

</div>

Dear Plots wizards—macos. julia 1.0.0. Plots.jl with standard gr() backend. Vanilla install. Please type this in:

```julia
$ julia

julia> using Plots

julia> plot( [-1,10], [-1,10], color=Gray(0.5), w=30, title="gray scale" )

julia> for i=0:10; vline!( [i], color=Gray(i/10.0), w=10 ) end

```

If you see what I see, it is the diagonal line, but no vertical lines. I have tried this with newly restarted julias, GKSTerm, etc. however, if I do a savefig(), the vertical lines do show up. similarly, if in the julia REPL, I type now (following the above)

```julia
julia> hline!( [2.0], color=Gray(0.3))

```

the vertical lines suddenly appear, too. it’s as if Plots forgot to tell GKSTerm to redraw until it is woken up by the hline. or maybe I am doing something wrong altogether? and/or can I force a redraw?

* * *

And, this was a debug run itself—I wanted to show off a gray spectrum. but why does the following only draw black vertical bars?

```julia
julia> vline!( 0:10, color=Gray.(reshape(collect(0.0:0.1:1.0),1,11)), w=20 )

```

And the incorrect vector argument (`vline!( 0:10, color=Gray.(collect(0.0:0.1:1.0)), w=20 )` is also baffling.

Any advice would be appreciated.

---

<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:** [September 18, 2018, 10:36am UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/2 "2018-09-18T10:36:03Z")

</div>

This is a scoping issue. Change your code to:

```julia
p = plot( [-1,10], [-1,10], color=Gray(0.5), w=30, title="gray scale" )

for i=0:10
    vline!(p, [i], color=Gray(i/10.0), w=10 ) 
end

display(p)

```

And it should work

Edit to add output:

![greyscale](https://global.discourse-cdn.com/julialang/original/3X/0/3/030cc4dcacba3a58ed302fa4c203d3c041cd15e5.png)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 18, 2018, 11:30am UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/3 "2018-09-18T11:30:22Z")

</div>

Also, for support questions like these, you might want to go to our gitter channel: [tbreloff/Plots.jl - Gitter](https://gitter.im/tbreloff/Plots.jl)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 18, 2018, 11:45am UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/4 "2018-09-18T11:45:05Z")

</div>

Perhaps you could mention that gitter is the preferred support forum explicitly in the [README](https://github.com/JuliaPlots/Plots.jl).

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 18, 2018, 12:00pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/5 "2018-09-18T12:00:32Z")

</div>

There’s a “chat on gitter” badge? In my experience most users tend to look at the badges and ignore the text (people tended for a long time to say “Plots has no documentation” when it was linked twice in that short readme - but people seem to see the blue docs badge).

---

<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:** [September 18, 2018, 1:11pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/6 "2018-09-18T13:11:38Z")

</div>

Gitter chats these days seems to be dominated by slackbots - would it be worth advertising the slack channel as well?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [September 18, 2018, 1:42pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/7 "2018-09-18T13:42:14Z")

</div>

Just to clarify: the existence of a gitter channel is clear, the fact that it is the preferred support option is not.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 18, 2018, 3:35pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/8 "2018-09-18T15:35:59Z")

</div>

and then there are people like myself, who have never used gitter, barely used slack, and who are astonished by the fact that a cacophony (without titles on conversations) could ever work. does it really?

(nilshg—could you please point me to where to read up on scoping issues in this context? I am completely unaware of this. I only knew of scoping issues in terms of variables and functions.)

---

<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:** [September 18, 2018, 9:43pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/9 "2018-09-18T21:43:13Z")

</div>

Actually I think I misinterpreted this error - my initial thought was that the issue here was that the mutating `vline!` function couldn’t see the plot object defined outside the loop, but upon further reflection I think the issue is rather that the `for` loop doesn’t return the `Plot` object.

I think a simpler example is:

```julia
a = 0
for i = 1:10  
  a += 1 # or global a in 1.0
end

```

This snippet returns `Nothing` - if I want to actually see what happened to `a` after the loop, I’ll have to explicitly call `a`.

Similarly, your original code _did_ work, you just didn’t see the result. I thought I had solved the problem by assigning the plot object to a variable `p`, and then passing this as an argument to `vline!`. It turns out that this isn’t actually necessary, the key thing is simply that with the assignment to `p` we have a way of referencing the plot object in a `display()` call after the loop. My example therefore would have also worked without passing `p` to `vline!`:

```julia
p = plot( [-1,10], [-1,10], color=Gray(0.5), w=30, title="gray scale" )

for i=0:10
    vline!([i], color=Gray(i/10.0), w=10 ) 
end

display(p)

```

Apologies for the confusion!

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [September 18, 2018, 10:41pm UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/10 "2018-09-18T22:41:19Z")

</div>

Mille Grazie. This explanation helped. I had forgotten that the for was treated like one big statement by the REPL, and thus returned nothing and not the final vline.

any idea why neither of the following produces the same?

```julia
julia> vline!( 0:10, color=Gray.(reshape(collect(0.0:0.1:1.0),1,11)), w=20 ) ## only black bars

```

wouldn’t produce the right graph? the following works, but how do 11 bars use up 31 gray values:

```julia
vline!(p, 0:10, color=Gray.( range(0.0, stop=1.0, length=31 )), w=20 )

```

---

<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:** [September 19, 2018, 7:41am UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/11 "2018-09-19T07:41:48Z")

</div>

Can’t quite work it out but it appears `color` expects a column vector, while your reshape produces a row vector (1x11 Array). Slight improvement:

```julia
vline!( 0:10, color=[Gray(0.0 + i*0.1) for i ∈ 0:10], w=10 )  

```

or alternatively transposing your original:

```julia
vline!( 0:10, color=Gray.(reshape(collect(0.0:0.1:1.0),1,11))', w=10 )  

```

Now for some reason this seems to cycle through 4 shades of gray rather than plotting all 11, but it gets you a bit closer to where you want to be…

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 19, 2018, 8:53am UTC](https://discourse.julialang.org/t/redraw-in-gksterm-asleep-and-gray-mysteries/15099/12 "2018-09-19T08:53:36Z")

</div>

There appears to be something wrong with the implementation of `vline!`? This syntax should work `vline!(0:10, line_z = 0:10, color = :grays)` but for some reason it does not.
