Makie: Mixing "spaces" while plotting

Hi, I have a quite simple question: Is there currently a way to plot something so that you can specify x and y coordinates in different spaces (i.e. x=10 absolute units; y=0.5 relative units w.r.t. the scene/axis height)? I can plot in a “relative space” using Makie.camrelative(myscene) (for the pixel camera at least), but mixing different spaces seems impossible due to Makie’s design.

And if I had to handle the transformation myself, would “Observables” be the way to go, or is there another way? I just want to make sure I’m not missing something here.

If you want to adventure into the land of open pull requests https://github.com/JuliaPlots/Makie.jl/pull/1730 does it. If not you need to work out what your coordinates are in a common space defined by the camera of the scene.

Assuming absolute units means pixel units you’ll need the pixel size of the scene scene.camera.resolution. With that you can switch between relative and pixel units. Something like this should do it: (With camrelative)

x = Observable([0, 10])
transformed_x = map(x, scene.camera.resolution) do x, size
    x / size[1]
end
1 Like

Ah, I had seen #1596. but somehow missed the newer one. This looks actually like pretty much what I want.

Would this also work with a bare scene or does it somehow depend on using an Axis() (given that it supports :data coordinates)?

It works with any scene as long as spaces don’t get mixed in some way (i.e. as long as there are no rotations).
:data coordinates don’t directly relate to Axis either. You can think of space = :data as using what the camera/scene/axis is set to and the other cases as overwrites. If you use a scene with a pixel camera space = :data will result in pixel space, for example.

Edit: Commenting out the corresponding line in precompiles.jl “fixes” the problem, but obviously something is still broken. Otherwise, I’ll be very happy to see this in master soon (and eventually in the stable release). Thanks!

Ok, this seems to be exactly what I’m after. What a timing :). However, I can’t seem to CairoMakie from your ff/transform branch. I know it’s WIP, so I’m not going to open an issue but here’s the error message:

 Precompiling CairoMakie [13f3f980-e62b-5c42-98c6-ff1f3baf88f0]
ERROR: LoadError: MethodError: no method matching space_to_clip(::Makie.Camera, ::Type{MakieCore.Pixel})
Closest candidates are:
  space_to_clip(::Makie.Camera, ::Tuple) at ~/.julia/packages/Makie/qmr6L/src/camera/projection_math.jl:328
  space_to_clip(::Makie.Camera, ::Tuple, ::Bool) at ~/.julia/packages/Makie/qmr6L/src/camera/projection_math.jl:328
  space_to_clip(::Makie.Camera, ::Symbol) at ~/.julia/packages/Makie/qmr6L/src/camera/projection_math.jl:314
  ...

That probably means you’re behind on MakieCore, Makie or CairoMakie. My guess is on MakieCore because 1730 doesn’t change it but 1596 did.

I had actually dev’d MakieCore and CairoMakie as well. But other than the precompilation error and some stuff related to the show_axis keyword for scenes, it seems to work fine. I’m happy to wait until it’s merged and then report any issues :slight_smile: