plotjuliaheatmapplots.jl

Change number of breaks in colorbar heatmap Julia


I am trying to change the number of breaks in the legend of a heatmap. I am using the example from docs to make it reproducible:

using Unitful, Plots

xs = [string("x", i) for i = 1:10]
ys = [string("y", i) for i = 1:4]
z = float((1:4) * reshape(1:10, 1, :)) * u"km"
heatmap(xs, ys, z, aspect_ratio=1)

Output:

enter image description here

Imagine I want for example only 4 breaks so: 5, 15, 25, 35. How can we change the number of breaks in a heatmap in Julia?


Solution

  • You can use colorbar_ticks but they are not supported by gr() so you will need to switch to pyplot() backend:

    pyplot()
    heatmap(xs, ys, z, aspect_ratio=1, colorbar_ticks=[5, 15, 25, 35] .* u"km")
    

    enter image description here