How to translate and scale Makie.image?

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

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.

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

This MWE demonstrates the problem, @jules:

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

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

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.

1 Like

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.