# Setting both color maps and opacity when plotting rasters and heatmaps with Makie

**URL:** <https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600>\
**Category:** Visualization\
**Tags:** makie, rasters\
**Created:** [November 2, 2025, 6:48am UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600 "2025-11-02T06:48:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugenetkj98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eugenetkj98/32/25309_2.png) [@eugenetkj98](https://discourse.julialang.org/u/eugenetkj98)\
**Post date:** [November 2, 2025, 6:48am UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/1 "2025-11-02T06:48:48Z")

</div>

Hi all, I’m looking to make a plot of some rasters (or if all else fails heatmaps) of values using Makie where the base color is independent of the opacity. Trying to blend two bits of information here where there are two different arrays, one for the colorrange, and one for alpha values.

From looking at the gallery and docs, they all mostly show alpha being fed in as a single parameter. Is there a way to achieve the above?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 2, 2025, 9:13am UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/2 "2025-11-02T09:13:11Z")

</div>

If you don’t have a specific package in mind, check the `viz` recipe in GeoStats.jl. You can pass a vector of alpha to achieve the desired result.

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [November 2, 2025, 1:51pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/3 "2025-11-02T13:51:31Z")

</div>

See a small `imagealpha()` recipe I shared some time ago here on discourse: [How to implement Value Suppressing Colormaps in Makie - #6 by aplavin](https://discourse.julialang.org/t/how-to-implement-value-suppressing-colormaps-in-makie/129140/6)  
Maybe `image()` should just support `alpha=matrix` natively?..

---

<div class="post-metadata">

**Author:** ![eugenetkj98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eugenetkj98/32/25309_2.png) [@eugenetkj98](https://discourse.julialang.org/u/eugenetkj98)\
**Post date:** [November 3, 2025, 2:29pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/4 "2025-11-03T14:29:52Z")

</div>

Thanks all for the suggestion. I had thought of `viz` but I think it only supports Polygonal data? The rasters would be matrix information.

As for the recipe by @aplavin, that certainly looks like an option. But I was having some trouble getting it to run as it seems Makie.MakieCore.color\_and\_colormap!() is not a function found in the library anymore. Has there been a change to the package perhaps?

The links were helpful in pointing to the Colorfy.jl package though. It’s a very in elegant solution, but I’ve tried using a scatter plot with :rect markers and precomputed colors with Colorfy.jl to produce a plot. But if any of you have more insights on the above, would be keen to hear!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [November 3, 2025, 3:10pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/5 "2025-11-03T15:10:40Z")

</div>

`viz` supports all types of geospatial domains, including grids.

Check

> **[How to work with "rasters"? · GeoStats.jl](https://juliaearth.github.io/GeoStatsDocs/stable/faq/rasters/)**
>
> Documentation for GeoStats.jl.

and read

> **[Geospatial Data Science with Julia](https://juliaearth.github.io/geospatial-data-science-with-julia/)**

if you would like to dive into this ecosystem.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [November 3, 2025, 3:29pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/6 "2025-11-03T15:29:43Z")

</div>

Here’s a manual solution, it’s not too difficult but yeah maybe Makie could have more convenience for it. I guess the reason it doesn’t is because a varying colormap plus varying alpha is difficult to interpret.

```julia-auto
mat = reshape(1:16, 4, 4)
alphas = reshape(repeat(range(0, 1, length = 8), 2), 4, 4)

mi, ma = extrema(mat)
cg = cgrad(:viridis)
# index into colormap with values scaled to [0, 1]
colors = getindex.(Ref(cg), (mat .- mi) ./ (ma - mi))
colors_alpha = Makie.to_color(tuple.(colors, alphas))

image(colors_alpha)

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/d/7/d72fbccdc72fa394678b8ec23cb7422072414815.jpeg)

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [November 3, 2025, 3:53pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/7 "2025-11-03T15:53:57Z")

</div>

> [@eugenetkj98](#):
>
> But I was having some trouble getting it to run as it seems Makie.MakieCore.color\_and\_colormap!() is not a function found in the library anymore. Has there been a change to the package perhaps?

Yes, Makie had a large breaking change recently. I don’t know where this specific function went, but you might try `Makie.color_and_colormap!` (ie, remove `MakieCore`).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [November 3, 2025, 5:44pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/8 "2025-11-03T17:44:51Z")

</div>

I don’t think that function was ever public, might as well have disappeared in a non breaking release

---

<div class="post-metadata">

**Author:** ![eugenetkj98](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eugenetkj98/32/25309_2.png) [@eugenetkj98](https://discourse.julialang.org/u/eugenetkj98)\
**Post date:** [November 13, 2025, 11:05pm UTC](https://discourse.julialang.org/t/setting-both-color-maps-and-opacity-when-plotting-rasters-and-heatmaps-with-makie/133600/9 "2025-11-13T23:05:30Z")

</div>

Thanks to suggestion by @juliohm, I’ve managed to get it to with the Rasters.jl rasters, and have some nice plots!

@jules @aplavin I did try that fix at first, but it didn’t seem to work so I suspect that function isn’t available unfortunately.
