# Can I use a categorical x/y variable in Makie?

**URL:** <https://discourse.julialang.org/t/can-i-use-a-categorical-x-y-variable-in-makie/103129>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [August 23, 2023, 8:14pm UTC](https://discourse.julialang.org/t/can-i-use-a-categorical-x-y-variable-in-makie/103129 "2023-08-23T20:14:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertulli](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Post date:** [August 23, 2023, 8:14pm UTC](https://discourse.julialang.org/t/can-i-use-a-categorical-x-y-variable-in-makie/103129/1 "2023-08-23T20:14:53Z")

</div>

Hi, I’d like to plot an heatmap using Makie (I don’t care about the backend). The data are stored in a 2D matrix, and the x/y dimensions are actually categorical, represented with a vector of strings. In Plots, I can do something like

```julia
julia> program_names = [t.program for t in results]
58-element Vector{String}:
 "bench_2mm_core2_1_100_100"
 "bench_2mm_orig"
 "bench_3mm_core2_1_100_100"
 "bench_3mm_orig"
 "bench_adi_core2_1_100_100"
 "bench_adi_orig"
 "bench_atax_core2_1_100_100"
 "bench_atax_orig"
 "bench_bicg_core2_1_100_100"
 "bench_bicg_orig"
 "bench_cholesky_core2_1_100_100"
 "bench_cholesky_orig"
 "bench_covariance_core2_1_100_100"
 "bench_covariance_orig"
 "bench_deriche_core2_1_100_100"
 "bench_deriche_orig"
 ⋮
 "bench_mvt_core2_1_100_100"
 "bench_mvt_orig"
 "bench_nussinov_core2_1_100_100"
 "bench_nussinov_orig"
 "bench_seidel_2d_core2_1_100_100"
 "bench_seidel_2d_orig"
 "bench_symm_core2_1_100_100"
 "bench_symm_orig"
 "bench_syr2k_core2_1_100_100"
 "bench_syr2k_orig"
 "bench_syrk_core2_1_100_100"
 "bench_syrk_orig"
 "bench_trisolv_core2_1_100_100"
 "bench_trisolv_orig"
 "bench_trmm_core2_1_100_100"
 "bench_trmm_orig"

julia> distance_matrix_measures = pairwise_difference(measures_vec)
58×58 Matrix{Quantity{Float64, 𝐋^2 𝐌 𝐓^-3, Unitful.FreeUnits{(W,), 𝐋^2 𝐌 𝐓^-3, nothing}}}:
         0.0 W -0.138593 W … -0.000670795 W -0.152928 W
    0.138593 W 0.0 W 0.137922 W -0.0143344 W
 0.000644075 W -0.137949 W -2.67202e-5 W -0.152284 W
    0.153729 W 0.0151362 W 0.153059 W 0.000801762 W
 0.000987496 W -0.137606 W 0.000316701 W -0.15194 W
 0.000341562 W -0.138252 W … -0.000329233 W -0.152586 W
  0.00310015 W -0.135493 W 0.00242935 W -0.149828 W
    0.149652 W 0.011059 W 0.148981 W -0.00327543 W
  0.00110525 W -0.137488 W 0.000434454 W -0.151822 W
    0.132496 W -0.00609756 W 0.131825 W -0.020432 W
    0.145352 W 0.00675866 W … 0.144681 W -0.00757578 W
    0.139371 W 0.000777863 W 0.1387 W -0.0135566 W
  0.00121418 W -0.137379 W 0.000543384 W -0.151714 W
    0.151652 W 0.0130586 W 0.150981 W -0.00127589 W
    0.118514 W -0.0200795 W 0.117843 W -0.0344139 W
    0.151647 W 0.0130542 W … 0.150977 W -0.00128026 W
             ⋮ ⋱                  
 0.000762225 W -0.137831 W 9.14301e-5 W -0.152165 W
    0.149316 W 0.0107225 W 0.148645 W -0.00361189 W
 0.000843365 W -0.13775 W 0.00017257 W -0.152084 W
     0.13425 W -0.00434351 W … 0.133579 W -0.0186779 W
  0.00074294 W -0.13785 W 7.21451e-5 W -0.152185 W
    0.158092 W 0.0194988 W 0.157421 W 0.00516438 W
 0.000947786 W -0.137645 W 0.000276991 W -0.15198 W
    0.132462 W -0.00613168 W 0.131791 W -0.0204661 W
  0.00110807 W -0.137485 W … 0.000437276 W -0.15182 W
      0.1351 W -0.00349302 W 0.134429 W -0.0178275 W
 0.000920184 W -0.137673 W 0.000249388 W -0.152007 W
    0.150186 W 0.0115928 W 0.149515 W -0.00274168 W
  0.00379128 W -0.134802 W 0.00312049 W -0.149136 W
    0.149627 W 0.0110334 W … 0.148956 W -0.00330104 W
 0.000670795 W -0.137922 W 0.0 W -0.152257 W
    0.152928 W 0.0143344 W 0.152257 W 0.0 W

julia> p_measures = heatmap(
       program_names,
       program_names,
       distance_matrix_measures,
       )

```

and the plot has the string as labels. In Makie I can’t figure out a way to do it. The best I could do is to tweak `xtickformat = v -> program_names`, but then the labels are not aligned. Is it possible to do better? Thanks

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [August 23, 2023, 8:28pm UTC](https://discourse.julialang.org/t/can-i-use-a-categorical-x-y-variable-in-makie/103129/2 "2023-08-23T20:28:05Z")

</div>

you might need something like

```julia
ax.xticklabelalign = (:right, :center)

```

take a look at this example: [heatmap with text - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/heatmaps/text_heatmap/)

---

<div class="post-metadata">

**Author:** ![bertulli](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Post date:** [August 23, 2023, 11:18pm UTC](https://discourse.julialang.org/t/can-i-use-a-categorical-x-y-variable-in-makie/103129/3 "2023-08-23T23:18:01Z")

</div>

Thanks, the linked post provided a solution, especially about

```julia
yticks = string.(collect(alphabet))
ax = Axis(fig[1, 1], yticks = (1:n, yticks))

```

If I wanted to show only **some** of the values, what should I do? Manually create an array with just some of the values, and pass in the tuple a collection of the indices selected?
