# Scale Division in Makie

**URL:** https://discourse.julialang.org/t/scale-division-in-makie/105650
**Category:** Visualization
**Created:** [November 1, 2023, 11:12am UTC](https://discourse.julialang.org/t/scale-division-in-makie/105650 "2023-11-01T11:12:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![vivekag7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vivekag7/32/202869_2.png) [@vivekag7](https://discourse.julialang.org/u/vivekag7)
#### Post date: [November 1, 2023, 11:12am UTC](https://discourse.julialang.org/t/scale-division-in-makie/105650/1 "2023-11-01T11:12:21Z")

</div>

Hi, I was wondering if there is a way to put a scale division in a heatmap plot using Makie. See the following plot as a reference, where I would like to implement both the line and the value in the corner that is positioned center-right:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/a/4ae6be6c9ed11d98c7cc634d72224848aa19f19b.jpeg)

If possible I would like to couple it to a specific pixel ratio, so let’s say I know each pixel has a “real” width Δx. I want to make sure that for different plots with different Δx, that the scale division takes up a certain amount of pixels C (constant for each plot), but calculates the corresponding value (C\*Δx) and displays it above the scale division.

Thanks in advance!

---

<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 1, 2023, 1:17pm UTC](https://discourse.julialang.org/t/scale-division-in-makie/105650/2 "2023-11-01T13:17:27Z")

</div>

One option would be to calculate the data distance covered by some pixel width by listening to `ax.finallimits` and `ax.scene.px_area`. Then you can calculate the line and text position in pixel space for the axis scene, and update accordingly. This only works when there’s no axis scale applied.

```julia
using DelimitedFiles

volcano = readdlm(Makie.assetpath("volcano.csv"), ',', Float64)

f = Figure()
ax = Axis(f[1, 1])
co = contourf!(volcano, levels = 10, colormap = :Blues)

relpoints = Observable(Point2f[(0, 0), (1, 1)])
label = Observable("label")
width_px = Observable(50.0)
offset_px = Observable(20.0)

linesegments!(ax, relpoints, space = :pixel, color = :black, linewidth = 5)
text!(ax, @lift(($relpoints[1] + $relpoints[2]) * 0.5), space = :pixel, align = (:center, :bottom), text = label, offset = (0, 5))

onany(ax.finallimits, ax.scene.px_area, width_px, offset_px) do lims, pxa, width_px, offset_px
    xmin, xmax = extrema(lims)[1]
    br = Makie.bottomright(pxa) - pxa.origin
    width_data = width_px / widths(pxa)[1] * widths(lims)[1]
    label[] = "$(round(width_data, sigdigits = 3)) km"

    relpoints[] = [
        br + Point2f(-width_px - offset_px, offset_px),
        br + Point2f(-offset_px, offset_px),
    ]
end

notify(ax.finallimits)

f

```
