# Is it possible to draw contour plot in Makie.jl from predefined x, y coordinates of z data points?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147>\
**Category:** Visualization\
**Tags:** question, plotting\
**Created:** [September 25, 2019, 7:40am UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147 "2019-09-25T07:40:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [September 25, 2019, 7:40am UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/1 "2019-09-25T07:40:25Z")

</div>

Hi, I am thinking how to quickly visualize 2D matrix, given with matrices X, Y of coordinates of corresponding data points in Z matrix. It will be used in real-time visualization of action potential propagation in cardiac tissue (X, Y will represent coordinates of irregularly placed cells).

Analogous MATLAB function would be `contour(X, Y, Z): specifies the *x* and *y* coordinates for the values in Z`.

Is it possible to do that in Makie.jl?  
Or is it only possible by using Interpotations package and pre-constructing 2D interpolated matrix? (I am considering real-time visualisation performance)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 25, 2019, 9:29am UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/2 "2019-09-25T09:29:03Z")

</div>

Can you show a running mock up example in julia? I’m not 100% sure how you want your data to look! If you do that, I can help you better to figure out the right Makie command!

---

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [September 26, 2019, 7:10am UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/3 "2019-09-26T07:10:23Z")

</div>

In my simulation cardiac tissue is modeled using _brick-wall_ architecture: rectangles represent cells, bold lines are junctions between cells (by which wave of excitation propagates):  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/3/438bb6f8722eca9543ca6ea30da8c9b9d2417153.png)  
I want each cell to be colored by its voltage.  
Also I did test simulation using simpler, _columnar_ (cells are arranged in a grid) architecture of cells network, that can be represented using heatmap:

 ![test](https://global.discourse-cdn.com/julialang/original/3X/4/2/42252d6b77b1d53c6ab1d3058a91ef4f332ed43e.gif)  
Previously, I did quite similar visualization of neural network in MATLAB, but using _columnar_ architecture and contour: [http://jgp.rupress.org/content/suppl/2016/02/11/jgp.201511488.DC1/JGP\_201511488\_V1.mp4](http://jgp.rupress.org/content/suppl/2016/02/11/jgp.201511488.DC1/JGP_201511488_V1.mp4)  
I am experimenting with contour and heatmap, which could give better performance for real-time and good representation of the process for publishing. Also I am thinking how to visualize _brick-wall_ architecture, maybe using mesh or poly?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 26, 2019, 9:34am UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/4 "2019-09-26T09:34:00Z")

</div>

Cool graphics!  
Using mesh should be pretty straight forward, just have a look at e.g. : [http://juliaplots.org/MakieReferenceImages/gallery//fem\_mesh\_2d/index.html](http://juliaplots.org/MakieReferenceImages/gallery//fem_mesh_2d/index.html)

---

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [September 28, 2019, 3:34pm UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/5 "2019-09-28T15:34:12Z")

</div>

Thanks, I coded simple triangles mesh, it does show up. But when I try to animate it doesn’t update.  
Here is the code:

```julia
using Makie
function run2()
    s = Scene()
    sizeX = 10
    sizeY = 10
    points = zeros(sizeY * sizeX, 2)
    color = zeros(sizeY * sizeX)
    conn = zeros(Int64, (sizeY - 1) * (sizeX - 1), 3)
    conn2 = zeros(Int64, (sizeY - 1) * (sizeX - 1), 3)
    for y = 1:sizeY
        for x = 1:sizeX
            points[(y-1)*sizeX+x, 1] = x
            points[(y-1)*sizeX+x, 2] = y
            color[(y-1)*sizeX+x] = rand()
        end
    end
    for y = 1:sizeY-1
        for x = 1:sizeX-1
            # @infiltrate (y-1)*(sizeX-1)+x > 80
            conn[(y-1)*(sizeX-1)+x, 1] = Int((y - 1) * (sizeX) + x)
            conn[(y-1)*(sizeX-1)+x, 2] = Int((y - 1) * (sizeX) + x + 1)
            conn[(y-1)*(sizeX-1)+x, 3] = Int((y + 1 - 1) * (sizeX) + x)
            conn2[(y-1)*(sizeX-1)+x, 1] = Int((y + 1 - 1) * (sizeX) + x)
            conn2[(y-1)*(sizeX-1)+x, 2] = Int((y + 1- 1) * (sizeX) + x + 1)
            conn2[(y-1)*(sizeX-1)+x, 3] = Int((y - 1) * (sizeX) + x + 1)
        end
    end
    s = scatter!(points)
    mesh!(s, points, [conn; conn2], color = color, shading = false)
    # wireframe!(s[end][1], color = (:black, 0.6), linewidth = 3)
    for i = 1:100
        s[end][:color] = rand(100);
        update!(s)
        update_limits!(s)
        sleep(1/24)
    end
end
run2()

```

Other code using similar for loop is updating if I use heatmap. Also command `s[end][:color] = rand(100);` is updating mesh from REPL.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 28, 2019, 3:48pm UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/6 "2019-09-28T15:48:53Z")

</div>

For me it does update… Do you mean it doesn’t display?  
Because you’re missing a `display(s)` before the animation loop!

---

<div class="post-metadata">

**Author:** ![KestutisMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kestutisma/32/7835_2.png) [@KestutisMa](https://discourse.julialang.org/u/KestutisMa)\
**Post date:** [September 28, 2019, 3:55pm UTC](https://discourse.julialang.org/t/is-it-possible-to-draw-contour-plot-in-makie-jl-from-predefined-x-y-coordinates-of-z-data-points/29147/7 "2019-09-28T15:55:17Z")

</div>

Really! It worked now. Thanks.
