# Makie: Mixing "spaces" while plotting

**URL:** <https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [March 8, 2022, 12:18pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581 "2022-03-08T12:18:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [March 8, 2022, 12:18pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/1 "2022-03-08T12:18:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [March 8, 2022, 2:08pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/2 "2022-03-08T14:08:58Z")

</div>

If you want to adventure into the land of open pull requests [https://github.com/JuliaPlots/Makie.jl/pull/1730](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)

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

```

---

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [March 8, 2022, 3:31pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/3 "2022-03-08T15:31:29Z")

</div>

Ah, I had seen [#1596](https://github.com/JuliaPlots/Makie.jl/pull/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)?

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [March 8, 2022, 3:42pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/4 "2022-03-08T15:42:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [March 8, 2022, 5:18pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/5 "2022-03-08T17:18:51Z")

</div>

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:

```julia
 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
  ...

```

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [March 8, 2022, 10:33pm UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/6 "2022-03-08T22:33:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marcpabst](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@marcpabst](https://discourse.julialang.org/u/marcpabst)\
**Post date:** [March 9, 2022, 10:24am UTC](https://discourse.julialang.org/t/makie-mixing-spaces-while-plotting/77581/7 "2022-03-09T10:24:57Z")

</div>

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 `scene`s, it seems to work fine. I’m happy to wait until it’s merged and then report any issues 🙂
