# UnicodePlot exercise

**URL:** <https://discourse.julialang.org/t/unicodeplot-exercise/61101>\
**Category:** General Usage\
**Tags:** question, plotting, unicode\
**Created:** [May 13, 2021, 6:38pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101 "2021-05-13T18:38:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 13, 2021, 6:38pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/1 "2021-05-13T18:38:39Z")

</div>

I’ve taken up a little challenge to reproduce a classic plot from Chorin 1973 (maybe the first computerized flow plot ever) and I hoped `WaterLily.jl` + `UnicodePlots.jl` could make short work of it.

 ![Screen Shot 2021-05-13 at 19.11.35](https://global.discourse-cdn.com/julialang/original/3X/7/0/70ce381f06e533b0701ffe2d9b2ba4e66437a5e9.png)

However, to really nail this plot I need to limit myself to the the ‘x’ and ‘o’ characters, _downgrading_ `UnicodePlot.jl` significantly. I can get the coordinates where the x’s and o’s should be. I’m not having any luck adding x’s and o’s to the plot at those points. Any ideas?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 13, 2021, 7:04pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/2 "2021-05-13T19:04:10Z")

</div>

By the way - here is the `UnicodePlot.jl` output so far. It’s certainly cute, just not quite the right aesthetic.

![Screen Shot 2021-05-13 at 20.03.49](https://global.discourse-cdn.com/julialang/original/3X/1/2/129560ad2333d61e7ae4e67916ec6b04b9e80721.png)

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 13, 2021, 8:24pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/4 "2021-05-13T20:24:45Z")

</div>

Related question! Is there an easy way to repeatedly update the terminal output, making this into a video? I saw [GitHub - IanButterworth/VideoInTerminal.jl: Video playback in terminal via. ImageInTerminal.jl and VideoIO.jl](https://github.com/IanButterworth/VideoInTerminal.jl), and the code to refresh the REPL output must be in there somewhere… but I’m not seeing where.

---

<div class="post-metadata">

**Author:** ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Post date:** [May 13, 2021, 8:35pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/6 "2021-05-13T20:35:03Z")

</div>

This looks great!

---

<div class="post-metadata">

**Author:** ![Ribeiro](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ribeiro](https://discourse.julialang.org/u/Ribeiro)\
**Post date:** [May 13, 2021, 8:41pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/7 "2021-05-13T20:41:43Z")

</div>

Wouldn’t it be easier to do this manually? Like a simple sweep through the mesh that prints spaces, Xs, and Os, depending on the values? I feel like trying to simplify UnicodePlots would be more work than that.  
(I assume O is for positive vorticity, X negative. Never seen that plot before, so thanks for that =])

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 13, 2021, 8:48pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/8 "2021-05-13T20:48:31Z")

</div>

Yes, the x’s denotes positive vorticity and o’s are negative.

Is there an easy way to reproduce the nuts and bolts of UnicodePlots display without the package? It must be some kind of specialized print output.

---

<div class="post-metadata">

**Author:** ![Ribeiro](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ribeiro](https://discourse.julialang.org/u/Ribeiro)\
**Post date:** [May 13, 2021, 8:58pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/9 "2021-05-13T20:58:41Z")

</div>

No idea, but why can’t you just print the results of the mesh to the terminal? You’d have to do too much interpolation or something?  
In other words, which feature of UnicodePlots is needed for this?

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 13, 2021, 10:24pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/10 "2021-05-13T22:24:07Z")

</div>

I am generally trying to use other people’s code instead of just writing my own where possible in Julia. In this case, it is easy enough:

```julia
function print_vort(a)
    width,height = size(a)
    for w in 2:4:width-1
        s = ""
        for h in 2:2:height-1
            v = sum(a[w:w+4,h:h+1])/8
            s*= v<-1 ? "O" : v>1 ? "X" : " "
        end
        println(s)
    end
end

julia> print_vort(a)

                             
            XXX OO             
           XX OO            
          XX OO           
          XX OO           
          XX OOOO OOO          
           XXXXXX OOO          
           XXXXXXX OOO          
            XXXXXXXOOO          
                   OOO          
                 OOOOO          
            OOOOOOOOO           
          OOOOOOOOO             
           OOOO                 
                                
                                
                                
           XXXXXXXXXX           
         XXXXXXXXXXX            
        XXXXXXXXX               
         XXXX                   
                                
                                
                                
                  OOOOO         
                OOOOOOO         
               OOOOOOOO         
               OOOOOO           

```

---

<div class="post-metadata">

**Author:** ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)\
**Post date:** [May 14, 2021, 1:36pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/11 "2021-05-14T13:36:17Z")

</div>

Gnuplot can plot using the characters you specify. An example with `X` and `O` with Gaston:

```julia
using Gaston
x1 = randn(10); y1 = randn(10);
x2 = randn(10); y2 = randn(10);
plot(x1, y1, w = "points", marker = "X", lc = :black);
plot!(x2, y2, w = "points", marker = "O", lc = :black)

```

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

Gnuplot can also plot using ASCII text on the terminal by setting the terminal to `dumb`:

```julia
      +--------------------------------------------------------------------+
      | X + + + + + + + + + |
  1.5 |-+ +-|
      | X |
    1 |-+ +-|
      | X X |
  0.5 |-+ O +-|
      | X O O |
      | O O |
    0 |-+ X +-|
      | O |
 -0.5 |-+ O O X +-|
      | |
   -1 |-+ X +-|
      | |
 -1.5 |-+ X +-|
      | |
      | O |
   -2 |-+ X+-|
      | + + + O + + + + + + |
 -2.5 +--------------------------------------------------------------------+
            -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

```

There are two julia front-ends to Gnuplot I’m aware of: [Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl) and [Gaston](https://github.com/mbaz/Gaston.jl).

---

<div class="post-metadata">

**Author:** ![weymouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/weymouth/32/15839_2.png) [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Post date:** [May 14, 2021, 8:47pm UTC](https://discourse.julialang.org/t/unicodeplot-exercise/61101/12 "2021-05-14T20:47:19Z")

</div>

looks nice. i’ll check it out.
