# Plots in the terminal (with sixel)

**URL:** <https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503>\
**Category:** Visualization\
**Tags:** plotting, repl\
**Created:** [March 29, 2019, 2:58pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503 "2019-03-29T14:58:45Z")\
**Posts on this page:** 11\
**Page:** 3

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [May 3, 2023, 8:29am UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/41 "2023-05-03T08:29:56Z")

</div>

> [@jheinen](#):
>
> `usecolorscheme(2)`

Works like a charm, thanks for the swift and effective reply.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/3/d31cc614214dd6066ba2d9b8b1bb6c872809b7ed.png)

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [May 3, 2023, 8:49am UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/42 "2023-05-03T08:49:22Z")

</div>

@jheinen If I do the following setup:

```julia
julia> inline("iterm", false);

julia> for f in range(0.5, 5, 100)
           ts = range(0, 2π, 1000)
           plot(ts, sin.(2π .* ts .* f))
           sleep(0.0001)
       end

```

I get the following output, with the plot updating in-place (thanks to the `false` argument to `inline`)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/9/d9354ac836b2f741cceed079d5479fdb2f370e1f.png)

However, subsequent plots end up on top of the code previously run:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/a/1ab253deb767ec6ef63ae6387d3bf758330e8d25.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/f/cf89b0b9e7dc933ff0a49cc23c9549f13108275c.png)

Until I make a new call to `inline("iterm", false)` before plotting. When I do that, it “resets”, and for the first new plot, makes sure to push the previous terminal content up to make room for the new plot.

This behavior does not seem ideal, as I assume most users would always want the previous input pushed up in the terminal to make room for the plot. Am I using it wrong, is it something easily fixable, or should I make a bug report?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [May 3, 2023, 11:19am UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/43 "2023-05-03T11:19:24Z")

</div>

I apologize if I missed something, but I tried this in the default Julia terminal and nothing shows up?

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 3, 2023, 12:53pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/44 "2023-05-03T12:53:30Z")

</div>

What do you men with “default Julia terminal”? You need sth like [iTerm2](https://iterm2.com) or any compatible app.

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 3, 2023, 12:54pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/45 "2023-05-03T12:54:09Z")

</div>

I changed the cursor movement in `GR#master`. I hope that fixes your problem …

BTW: the color scheme should now be set automatically (in dark mode).

---

<div class="post-metadata">

**Author:** ![devel-chm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devel-chm/32/3572_2.png) [@devel-chm](https://discourse.julialang.org/u/devel-chm)\
**Post date:** [May 3, 2023, 1:28pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/46 "2023-05-03T13:28:18Z")

</div>

On windows systems, even with a sixel capable terminal,  
there appears to be something which disables the output  
that is specific to windows.

[This discourse post](https://discourse.julialang.org/t/terminal-control-characters-to-xterm-mintty-blocked-on-windows/94006) has some discussion and other  
links for reference.

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [May 3, 2023, 1:38pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/47 "2023-05-03T13:38:11Z")

</div>

I can confirm on master, that the default theme works, and that the plot no longer happens on top of the previous command after `inline("iterm", false)`. Instead, there is now a large blank space above the plots after the first plot (recall that the first plot after `inline` behaves differently).

I will put the plots into a fold-out, as they are pretty long:

> ****
>
> With the second argument to inline set to `true` we get plain printing of one after the other:
> 
> ![image](https://global.discourse-cdn.com/julialang/original/3X/f/2/f290f1614364fcc45021d20532a3b23de1030b70.png)
> 
> Setting it to false and then making two plots now causes a funny space above it, and overwrites the call to `inline` with the second argument to false.
> 
> ![image](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f79c8af6010eaf532f7c151d31f59599b0051a6.png)  
> ![image](https://global.discourse-cdn.com/julialang/original/3X/4/8/48471738eab9b5b438e69a60fb9a84843eb31e9a.png)

So all in all, the behaviour from `inline("iterm")` is the same, and when setting the second argument to false, it is worse IMO. The automatic colortheme is supernice though.

Edit: The command I use (my application is live oscilloscope plotting) is as follows, for testing:

```julia
for f in range(1e-2, 1, 100)
          ts = range(0, 2π, 1000)
          plot(ts, sin.(2π .* ts .* f))
          sleep(0.001)
       end

```

---

<div class="post-metadata">

**Author:** ![jheinen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jheinen/32/2787_2.png) [@jheinen](https://discourse.julialang.org/u/jheinen)\
**Post date:** [May 3, 2023, 1:47pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/48 "2023-05-03T13:47:14Z")

</div>

> [@TheLateKronos](#):
>
> Instead, there is now a large blank space above the plots after the first plot (recall that the first plot after `inline` behaves differently).

I have currently no idea how to make it more convenient. Overplotting and scrolling is somehow tricky. If you have any ideas, just let me know.

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [May 3, 2023, 2:05pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/49 "2023-05-03T14:05:44Z")

</div>

Right. I have no clue, so for now, the best solution I see is to keep the colortheme change, and revert the other one. At least then, it is possible to run `inline` once before a plotting-loop to get the desired behavior.

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [June 13, 2023, 12:26pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/50 "2023-06-13T12:26:48Z")

</div>

> [@jheinen](#):
>
> I have currently no idea how to make it more convenient. Overplotting and scrolling is somehow tricky. If you have any ideas, just let me know.

`print(stdout, "\x1b[s")` saves the cursor position, and `print(stdout, "\x1b[u")` restores it. Also, `print(stdout, "\x1b[H\x1b[2J")` clears the terminal. I noticed that if I clear the terminal in a loop, the plot flickers, as it is empty for a moment before the new one is drawn and printed. But I do not think that the sixel plots actually overwrite completely, so that the effect without clearing the terminal is perhaps just the two plots stacked on top of each other. But those ANSI codes should at least be able to help with getting the desired behaviour.

Do you believe it is possible to set a non-transparent background for the plot? That should make it possible to overdraw (using the save and restore ASCI codes), and avoid having the plots overlapp.

Note: I believe that these ANSI codes are not supported on the default windows terminal, so there could be platform dependent behaviour. WindowsTerminal should however support it.

---

<div class="post-metadata">

**Author:** ![caleb-allen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/caleb-allen/32/14054_2.png) [@caleb-allen](https://discourse.julialang.org/u/caleb-allen)\
**Post date:** [August 9, 2023, 4:25pm UTC](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503/51 "2023-08-09T16:25:58Z")

</div>

It looks like the terminal within vs-code will soon support image display!

> <https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_80.md#terminal>

[Previous page](https://discourse.julialang.org/t/plots-in-the-terminal-with-sixel/22503.md?page=2)
