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

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)

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!

1 Like

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
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:


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
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?

1 Like

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

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

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.

1 Like

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

Really! It worked now. Thanks.