# How to make a heatmap with pgfplotsx?

**URL:** <https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128>\
**Category:** Visualization\
**Tags:** pgfplotsx\
**Created:** [January 24, 2022, 2:01pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128 "2022-01-24T14:01:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [January 24, 2022, 2:01pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128/1 "2022-01-24T14:01:37Z")

</div>

Hi there! Which is the straightforward pgfplotsx way to make heatmap figure? For Plots is so easy:

```julia
V = rand(20, 20)
heatmap(V)

```

Thanks in advanced!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 24, 2022, 2:20pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128/2 "2022-01-24T14:20:31Z")

</div>

[https://kristofferc.github.io/PGFPlotsX.jl/v1/examples/juliatypes/#D-2](https://kristofferc.github.io/PGFPlotsX.jl/v1/examples/juliatypes/#D-2)

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [January 24, 2022, 2:40pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128/3 "2022-01-24T14:40:01Z")

</div>

Yes, well, I was doing some stuff in this way but I obtain some kind of interpolation…

```julia
w = range(1; stop = 30, length = 30)
@pgf Axis(
    {
        view = (0, 90),
        colorbar,
        "colormap/jet"
    },
    Plot3(
        {
            surf,
            shader = "flat",

        },
        Table(w, w, V))
)

```

![pp](https://global.discourse-cdn.com/julialang/original/3X/2/a/2af6e0427c248b33192a156c685a9b9e045938f4.png)

However, the correct plot must be…

![pp](https://global.discourse-cdn.com/julialang/original/3X/9/3/939b59f146b3cc897848778916df78c88697eaea.png)

---

<div class="post-metadata">

**Author:** ![ccmejia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ccmejia/32/18680_2.png) [@ccmejia](https://discourse.julialang.org/u/ccmejia)\
**Post date:** [January 24, 2022, 5:42pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128/4 "2022-01-24T17:42:39Z")

</div>

Well, I found a solution… But, probably it can be done in a more elegant way:

```julia
x = repeat(1:30, outer = 30)
y = repeat(1:30, inner = 30)
meta = vec(V)
c = Coordinates(x, y; meta = meta)
@pgf Axis(
    { height = "12cm", width = "12cm", colorbar,
        "colormap/jet",
        enlargelimits = false,
        xtick = [1, 5, 10, 15, 20, 25, 30],
        ytick = [1, 5, 10, 15, 20, 25, 30],
    },
    PlotInc(
        {
            matrix_plot,
            mark = " ",
            point_meta = "explicit",
            "mesh/cols" = 30
        },
        c,
    )
)

```

 ![pp](https://global.discourse-cdn.com/julialang/original/3X/9/3/93b50f935532b6e8a49ce0a2d4892c30f4d5d5aa.png)

---

<div class="post-metadata">

**Author:** ![tapyu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tapyu/32/37182_2.png) [@tapyu](https://discourse.julialang.org/u/tapyu)\
**Post date:** [June 27, 2026, 2:08pm UTC](https://discourse.julialang.org/t/how-to-make-a-heatmap-with-pgfplotsx/75128/5 "2026-06-27T14:08:07Z")

</div>

My two cents: For heavy weight heatmaps, the best approach is a two-step procedure:

1. Use `Coordinates()` to generate a time-consuming axisless heatmap in PDF/SVG format
2. Use `Graphics()` to to put this PDF into a axis and a colomap scale and generate a `.tex` file which should be integrated with the rest of the LaTeX project.

It avoids a time-consuming compulation of the LaTeX document. See my [snippets](https://gist.github.com/tapyu/e9b5425621db4f0ee6c9ae7194d439e9#file-graphics-jl) (`graphics.jl` and `heatmap_matrix_plot_colormap_bare.jl`) for a example where I do that for a spectrogram.
