# Heatmap with log scale colorbar (cscale)

**URL:** <https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018>\
**Category:** New to Julia\
**Tags:** plotting, makie\
**Created:** [June 16, 2021, 2:10pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018 "2021-06-16T14:10:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [June 16, 2021, 2:10pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/1 "2021-06-16T14:10:57Z")

</div>

Makie is awesome, looks like everything is doable 🙂,  
for instance, this heatmap with log scale color axis (exactly what I wanted):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/0/400ce2f601baff4251a1a8fee747d081b6c5c0f9.png)

> **Code for the above figure**
>
> ```julia
> # in one Pluto.jl cell
> using CairoMakie
> 
> # another Pluto.jl Cell
> let
> # cf. https://github.com/JuliaPlots/Makie.jl/issues/822#issuecomment-769684652
> # with scale argument that is required now
> struct LogMinorTicks end
> 	
> function MakieLayout.get_minor_tickvalues(
> ::LogMinorTicks, scale, tickvalues, vmin, vmax
> )
> vals = Float64[]
> for (lo, hi) in zip(
> @view(tickvalues[1:end-1]),
> @view(tickvalues[2:end])
> )
> interval = hi-lo
> steps = log10.(LinRange(10^lo, 10^hi, 11))
> append!(vals, steps[2:end-1])
> end
> vals
> end
> 	
> custom_formatter(values) = map(
> v -> "10" * Makie.UnicodeFun.to_superscript(round(Int64, v)),
> values
> )
> 	
> x = 10.0.^(1:0.1:4)
> y = 1.0:0.1:5.0
> data = x .* ones(Float64, 1, length(y))
> fig = Figure()
> ax, hm = heatmap(fig[1, 1], x, y, log10.(data),
> axis=(;xscale=log10,
> xminorticksvisible=true,
> xminorticks=IntervalsBetween(9))
> )
> cb = Colorbar(fig[1, 2], hm;
> tickformat=custom_formatter,
> minorticksvisible=true,
> minorticks=LogMinorTicks()
> )
> fig
> end
> 
> ```

But it was a bit involved for a newcomer. Here is how I would have expected it to work:

```julia
x = 10.0.^(1:0.1:4)
y = 1.0:0.1:5.0
data = x .* ones(Float64, 1, length(y))
fig = Figure()
ax, hm = heatmap(fig[1, 1], x, y, data,
	axis=(;xscale=log10, 
		   xminorticksvisible=true, xminorticks=IntervalsBetween(9),
		   cscale=log10)
         )
Colorbar(fig[1, 2], hm)

```

Currently (`CairoMakie v0.5.9`) the the `cscale` argument is just ignored:

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

I also tried `zscale` and read the documentation of course, in particular  
[http://makie.juliaplots.org/stable/makielayout/axis.html#Log-scales-and-other-axis-scales](http://makie.juliaplots.org/stable/makielayout/axis.html#Log-scales-and-other-axis-scales)

Would it make sense to add this `cscale` argument, for symetry with `xscale` or `yscale` ?  
It has exactly the same meaning:  
Actually plot log10(axis values) on an underlying linear axis,  
and instead of changing the label to log10(label),  
tweak ticks, minorticks and tick labels.

---

<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:** [June 16, 2021, 3:10pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/2 "2021-06-16T15:10:27Z")

</div>

you do the same in the Colorbar call, i.e.,  
`Colorbar(fig[1,2], pltHeat, scale = log10)`. Here, an example with log scales in all directions.  
[https://lazarusa.github.io/BeautifulMakie/heatmaps/heatmapLogIrregular/](https://lazarusa.github.io/BeautifulMakie/heatmaps/heatmapLogIrregular/)

unfortunately, I’m doing first a colormap with a logscale. `cmap = cgrad(:CMRmap, scale = :log)`, but is just one line, and it works.

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [June 16, 2021, 7:32pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/3 "2021-06-16T19:32:51Z")

</div>

Thanks for the answer, [BeautifulMakie](https://lazarusa.github.io/BeautifulMakie) will be useful.  
But I already tried that. The issue is that the colormap would not be the regular one.  
For instance, the blue area is smaller in the scaled colormap,  
and larger in the heatmap.  
With this test data, used especially to show that, the gradient should look like the colormap.

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

> **Code**
>
> ```julia
> let # to test in a Pluto cell
> x = 10.0.^(1:0.1:4)
> y = 1.0:0.1:5.0
> data = x .* ones(Float64, 1, length(y))
> fig = Figure()
> cmap = cgrad(:viridis, scale=:log10)
> ax, hm = heatmap(fig[1, 1], x, y, data; colormap=cmap,
> axis=(;xscale=log10,
> xminorticksvisible=true,
> xminorticks=IntervalsBetween(9))
> )
> cb = Colorbar(fig[1, 2], hm;
> minorticksvisible=true,
> minorticks=IntervalsBetween(9),
> scale=log10
> )
> fig
> end
> 
> ```

---

<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:** [June 16, 2021, 8:08pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/4 "2021-06-16T20:08:44Z")

</div>

your are right. That’s definitely wrong. Probably you should file an issue in [Makie.](https://github.com/JuliaPlots/Makie.jl/issues)

---

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [October 23, 2021, 10:22pm UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/5 "2021-10-23T22:22:54Z")

</div>

It seems that this issue persists in Makie v0.15.3. Have you filed an issue in the repo?

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [October 24, 2021, 9:19am UTC](https://discourse.julialang.org/t/heatmap-with-log-scale-colorbar-cscale/63018/6 "2021-10-24T09:19:38Z")

</div>

Thanks for the reminder. To allow for further discussion here, I intended to let one week pass, which became months 🤦‍♂️.  
Just filed, with up to date Makie, plots and links:  
[https://github.com/JuliaPlots/Makie.jl/issues/1405](https://github.com/JuliaPlots/Makie.jl/issues/1405)
