# How to translate and scale Makie.image?

**URL:** <https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [January 12, 2024, 6:06pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741 "2024-01-12T18:06:44Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [January 12, 2024, 6:06pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/1 "2024-01-12T18:06:44Z")

</div>

`Makie.image` plots a set of pixels efficiently, assuming that the image starts at the origin `(0,0)` and that the pixels are of size `1x1`.

We tried to apply `Makie.scale!` and `Makie.translate!` to the result of `Makie.image` to correct the origin and spacing of the plot, but these operations move the plot to outside the visible area, i.e., the axis is not automatically adjusted to fit all objects in the scene.

Is there a function to automatically adjust the axis? Can it be called from inside a Makie recipe?

Alternatively, can we call `Makie.image` with custom origin and fixed spacing per dimension?

cc: @sdanisch

---

<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:** [January 12, 2024, 7:02pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/2 "2024-01-12T19:02:39Z")

</div>

try `image(xmin .. xmax, ymin .. ymax, data)`. I think the translate route is more efficient when updating, though, because it doesn’t affect the conversion pipeline.

---

<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:** [January 12, 2024, 7:17pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/3 "2024-01-12T19:17:49Z")

</div>

That only addresses the origin. What about the spacing? Also how to autoadjust the axis extent after the Makie.translate and Makie.scale?

---

<div class="post-metadata">

**Author:** ![eliascarv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eliascarv/32/22152_2.png) [@eliascarv](https://discourse.julialang.org/u/eliascarv)\
**Post date:** [January 19, 2024, 5:36pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/4 "2024-01-19T17:36:15Z")

</div>

This MWE demonstrates the problem, @jules:

```julia
using Makie
using GLMakie

@recipe(ScaledImage, img, x, y) do scene
  Attributes()
end

function Makie.plot!(plot::ScaledImage)
  image!(plot, plot.img, interpolate=false)
  scale!(plot, plot.x[], plot.y[])
  # how to adjust the axis after scaling the plot?
end

img = rand(1:9, 10, 10)
scaledimage(img, 2.5, 1.5)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/d/5/d5230421dd1c88001e0a5df0a38fc6fde73e763f.png)

In this case, how can we adjust the axis within a recipe?

---

<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:** [January 19, 2024, 5:50pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/5 "2024-01-19T17:50:46Z")

</div>

This is behavior of Makie that is not quite correct yet, I think the model matrix should be included in the limit calculations. If it was, you wouldn’t have to do anything special in the recipe.

---

<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:** [January 19, 2024, 6:02pm UTC](https://discourse.julialang.org/t/how-to-translate-and-scale-makie-image/108741/6 "2024-01-19T18:02:47Z")

</div>

Thank you @jules , should we convert the MWE above into an issue on Makie’s repo?

We need this feature in order to plot transformed grids more efficiently.
