# Using Luxor.Table to visualize Julia 2D matrix results in transposed view

**URL:** <https://discourse.julialang.org/t/using-luxor-table-to-visualize-julia-2d-matrix-results-in-transposed-view/112484>\
**Category:** General Usage\
**Tags:** tables, luxor, matrix\
**Created:** [April 3, 2024, 8:04pm UTC](https://discourse.julialang.org/t/using-luxor-table-to-visualize-julia-2d-matrix-results-in-transposed-view/112484 "2024-04-03T20:04:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julia2001](https://avatars.discourse-cdn.com/v4/letter/j/bc79bd/32.png) [@Julia2001](https://discourse.julialang.org/u/Julia2001)\
**Post date:** [April 3, 2024, 8:04pm UTC](https://discourse.julialang.org/t/using-luxor-table-to-visualize-julia-2d-matrix-results-in-transposed-view/112484/1 "2024-04-03T20:04:02Z")

</div>

Hi, I’m stumbling across the fact that Luxor.Table looks row-major but Julia matrices are column-major.  
How can I “swap” dimension indices between source matrix read access and Luxor.Table write access?

```julia
using Luxor

width = 100
height = 100

m = [[1,2] [3,4]]

table = Table(size(m)[2], size(m)[1], 20, 20, Point(width / 2, height / 2))

Drawing(width, height, :rec)
background("darkgray")
fontsize(22)
fontface("Monaco")
sethue("red")

for n in eachindex(table)
    Luxor.text(string(m[n]), table[n], halign=:center, valign=:middle)
end

snapshot(fname=string(@ __DIR__ , "/tmp/test.png"))

finish()

display(m)

```

Result:  
 ![test](https://global.discourse-cdn.com/julialang/original/3X/9/a/9ad33e39c80c352afb6a6de548974d45faf3af11.png)

display(m) output:

```julia
2×2 Matrix{Int64}:
 1 3
 2 4

```

My experiments with the CartesianIndices() iterator failed so far. I want to avoid permutedims(m) because this seems to be slow, but I may be wrong about this…

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [April 4, 2024, 7:34am UTC](https://discourse.julialang.org/t/using-luxor-table-to-visualize-julia-2d-matrix-results-in-transposed-view/112484/2 "2024-04-04T07:34:55Z")

</div>

You could iterate the matrix:

```julia
@draw begin
    background("grey10")
    sethue("purple")
    fontsize(100)
    m = [[1, 2, 3] [4, 5, 6]]
    t = Table(size(m)..., 100, 100)
    for ci in CartesianIndices(m)
        row, col = Tuple(ci)
        text(string(m[row, col]),
            t[row, col],
            halign=:center,
            valign=:middle)
        circle(t[row, col], 50, :stroke)
    end
end

```

or iterate the table:

```julia
@draw begin
    background("grey10")
    sethue("purple")
    fontsize(100)
    m = [[1, 2, 3] [4, 5, 6]]
    t = Table(size(m)..., 100, 100)
    for cell in t
        row, col = t.currentrow, t.currentcol
        text(string(m[row, col]),
            t[row, col],
            halign=:center,
            valign=:middle)
        circle(t[row, col], 50, :stroke)
    end
end

```

with the same result:

 ![Screenshot 2024-04-04 at 08.22.09](https://global.discourse-cdn.com/julialang/original/3X/b/f/bf321787614b8f6b7bae3646a3c5abe2137509c3.png)

There are examples of using `CartesianIndices` in the docs.

> I want to avoid permutedims(m) because this seems to be slow, but I may be wrong about this…

Depends on the size of `m` I suppose. Perhaps you could benchmark it…
