# Custom divergent colormap with unequal sides

**URL:** <https://discourse.julialang.org/t/custom-divergent-colormap-with-unequal-sides/115484>\
**Category:** Visualization\
**Tags:** question, colors, makie\
**Created:** [June 11, 2024, 3:44pm UTC](https://discourse.julialang.org/t/custom-divergent-colormap-with-unequal-sides/115484 "2024-06-11T15:44:22Z")\
**Posts on this page:** 1\
**Showing post:** 8

<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:** [June 11, 2024, 9:33pm UTC](https://discourse.julialang.org/t/custom-divergent-colormap-with-unequal-sides/115484/8 "2024-06-11T21:33:40Z")

</div>

I’ve also seen plots where people use an uneven scale on a symmetrical colormap. So you don’t distort the map but the scale. Here’s an example I cooked up a while ago, adjusted to your numbers:

```julia
data = rand(10, 10) .* 4

f = Figure()
ax = Axis(f[1, 1])

upper = 4
lower = 0
midpoint = 1
ratio = (upper - midpoint) / (midpoint - lower)

sc = ReversibleScale(
    x -> x > midpoint ? (x - midpoint) / ratio + midpoint : x,
    x -> x > midpoint ? (x - midpoint) * ratio + midpoint : x
)

hm = heatmap!(ax, data, colorscale = sc, colorrange = (lower, upper), colormap = :delta)
Colorbar(f[1, 2], hm, ticks = lower:upper)
f

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e34559002f5452efb95bac32ed4ac8e1af832f3.png)

Here’s a variant with the upper part going to 10, to show the effect even more:

```julia
upper = 10
lower = 0
midpoint = 1

data = rand(10, 10) .* (upper - lower) .+ lower

f = Figure()
ax = Axis(f[1, 1])

ratio = (upper - midpoint) / (midpoint - lower)

sc = ReversibleScale(
    x -> x > midpoint ? (x - midpoint) / ratio + midpoint : x,
    x -> x > midpoint ? (x - midpoint) * ratio + midpoint : x
)

hm = heatmap!(ax, data, colorscale = sc, colorrange = (lower, upper), colormap = :RdBu)
Colorbar(f[1, 2], hm, ticks = lower:upper)
f

```

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

Might be confusing to some readers though.

Edit: hmm seems like the rendering of the colors in the heatmap is a bit off though with this

Edit2: I just had forgot to scale the input data with the larger limits, I think

---

_[View the full topic](https://discourse.julialang.org/t/custom-divergent-colormap-with-unequal-sides/115484)._
