# Can I draw a unicodeplot repeatedly without annoying shift on terminal?

**URL:** <https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112>\
**Category:** New to Julia\
**Tags:** repl, plots, unicode\
**Created:** [December 15, 2021, 3:41am UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112 "2021-12-15T03:41:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [December 15, 2021, 3:41am UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/1 "2021-12-15T03:41:45Z")

</div>

While following an example of [DiffEqFlux.jl](https://diffeqflux.sciml.ai/stable/examples/neural_ode_sciml/), I wanna change the backend of Plots.jl to do this remotely (via ssh).

However, repeatedly generated unicodeplot makes the terminal very annoying like:

```julia
74.84191276952308
            ┌────────────────────────────────────────┐
    2.11133 │⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ data
            │⠀⡇⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ prediction
            │⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⚬⚬⚬⚬⠀⚬⚬⠀⠀│
            │⠀⡇⚬⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀│
            │⠀⡇⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⚬⚬⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⚬⚬⚬⠀⚬⚬⚬⠀⚬⚬⚬⠀⚬⚬⚬⚬⠀⚬⚬⚬⠀│
            │⠉⡏⠉⠉⠉⠉⠉⚬⠉⠉⠉⠉⚬⠉⚬⚬⚬⠉⚬⠉⠉⠉⠉⚬⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
   -1.82238 │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⚬⠀⚬⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            └────────────────────────────────────────┘
            ⠀-0.045⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1.545⠀
72.33803421302132
            ┌────────────────────────────────────────┐
    2.11133 │⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ data
            │⠀⡇⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ prediction
            │⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⚬⚬⚬⚬⠀⚬⚬⠀⠀│
            │⠀⡇⚬⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⚬⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⚬⚬⠀⚬⠀⠀⠀⠀⠀⠀⠀⚬⚬⚬⚬⠀⚬⚬⚬⠀⚬⚬⚬⠀⚬⚬⚬⚬⠀⚬⚬⚬⠀│
            │⠉⡏⠉⠉⠉⠉⠉⚬⠉⠉⠉⚬⚬⠉⚬⚬⚬⠉⠉⠉⠉⠉⠉⚬⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
   -1.82238 │⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⚬⚬⠀⚬⚬⚬⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
            └────────────────────────────────────────┘
            ⠀-0.045⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1.545⠀

...

```

Is there any way to “reset” and “update” the existing unicodeplot?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 15, 2021, 6:22am UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/2 "2021-12-15T06:22:02Z")

</div>

Should be possible (ANSI to roll back `height+2*isinteractive()` lines before plotting) but I don’t think it’s implemented. You could make a feature request at the UnicodePlots.jl GitHub page.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [December 15, 2021, 7:41am UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/3 "2021-12-15T07:41:10Z")

</div>

[Check a solution here](https://discourse.julialang.org/t/clear-terminal-window/17046/4) to clear the REPL terminal:

```julia
write(stdin.buffer, 0x0C)

```

_NB: subsequent plots do stay in place:_

 ![Unicode_plots](https://global.discourse-cdn.com/julialang/original/3X/0/2/02cbfba5811c444e37347886779d1e9aaa3910d6.png)

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [December 15, 2021, 12:24pm UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/4 "2021-12-15T12:24:09Z")

</div>

For clearing up the whole terminal screen, on unix:

```julia
run(`clear`);

```

Otherwise @rafael.guerra 's solution is pretty decent.

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [December 15, 2021, 12:30pm UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/6 "2021-12-15T12:30:34Z")

</div>

> [@rafael.guerra](#):
>
> This does not seem to work in Windows:

That’s why I added `on unix`.

---

<div class="post-metadata">

**Author:** ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)\
**Post date:** [December 15, 2021, 12:34pm UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/7 "2021-12-15T12:34:40Z")

</div>

Just for fun:

```julia
julia> macro repeated(ex); :(run(`clear`); $(esc(ex))); end
julia> @repeated lineplot(sin)
julia> @repeated lineplot(cos)
...

```

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [December 15, 2021, 3:48pm UTC](https://discourse.julialang.org/t/can-i-draw-a-unicodeplot-repeatedly-without-annoying-shift-on-terminal/73112/8 "2021-12-15T15:48:46Z")

</div>

Also @pfitzseb 's [solution](https://discourse.julialang.org/t/clear-terminal-window/17046/9) works quite well, if your terminal supports escape codes:

```julia
for i in 1:10
      print("\e[0;0H\e[2J")
      display(plot(sin, 0, i))
      sleep(0.5)
end

```

meaning if you put the first two lines of the loop body in a callback, it should work as expected.
