# Multiple camera views on same scene in Makie

**URL:** https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274
**Category:** Visualization
**Tags:** makie
**Created:** [September 16, 2021, 3:56pm UTC](https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274 "2021-09-16T15:56:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [September 16, 2021, 3:56pm UTC](https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274/1 "2021-09-16T15:56:15Z")

</div>

I’d like to have two views of the same scene / data in Makie. Below is code for the output that I want, but I would like to just have one call to `scatter!` (for example).

```julia
using Makie: Makie, Observable
using GLMakie: GLMakie
using GeometryBasics: HyperRectangle

fig = Makie.Figure()
ax1 = Makie.Axis(fig[1, 1])
ax2 = Makie.Axis(fig[1, 2])

for ax in [ax1, ax2]
    Makie.scatter!(ax, [(0, 0), (1, 0), (0, 1)]; markersize=100)
end

window_size = (0.5, 0.5)
window_center = Observable((0.0, 0.0))

function make_rect_loop(center, size)
    ms = [(1, 1), (1, -1), (-1, -1), (-1, 1), (1, 1)]
    [center .+ (m .* size) for m in ms]
end

function make_rect(center, size)
    origin = center .- (size ./ 2)
    HyperRectangle{length(origin)}(origin, size)
end

window_corners = Makie.lift(c -> make_rect_loop(c, window_size), window_center)
viewport = Makie.lift(c -> make_rect(c, window_size), window_center)

# TODO endcap of path is not correct (does not close)
Makie.lines!(ax1, window_corners, color=:black, linewidth=5)
Makie.on(viewport) do vp
    Makie.limits!(ax2, vp)
end

display(fig)

secs = 3
framerate = 15
Makie.record(fig, "eg.mp4", 1:(secs * framerate); framerate) do i
    s = i / framerate
    kv = [(0, 0), (1, 0), (0, 1), (0, 0)]
    kt = [0.0, 1.0, 2.0, 3.0]
    # linear interpolation
    s_i = searchsortedfirst(kt, s)
    i1 = max(s_i - 1, firstindex(kv))
    i2 = min(s_i, lastindex(kv))
    Δ = kt[i2] - kt[i1][Processing: eg.mp4...]()
![eg|666x500](upload://6ht3x3ajm1XSbU9sbe01qPvvjU9.gif)

    p = ifelse(Δ == 0, 0.5, (s - kt[i1]) / Δ)
    v_s = kv[i1] .* (1 - p) .+ kv[i2] .* (p)
    window_center[] = v_s
end

```

![eg](https://global.discourse-cdn.com/julialang/original/3X/2/c/2c068e96dedb432542bd27e0aedf77e7c679fc7d.gif)

I’d also like to know what call truly forces the `Axes` limits, so that the black rectangle corresponds to the viewport of the right plot.

---

<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: [September 16, 2021, 4:11pm UTC](https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274/2 "2021-09-16T16:11:57Z")

</div>

If we’re talking about truly _force_, then you have to set `ax.finallimits[] = limits`. That could have unforeseen consequences though if you care about linking axes or limit aspects.

---

<div class="post-metadata">

### Author: ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)
#### Post date: [September 16, 2021, 4:14pm UTC](https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274/3 "2021-09-16T16:14:54Z")

</div>

I probably should consider going the other way around–drawing the rectangle based on `finallimits`.

The main point was to have two representations of the same underlying data. How possible is that with the current architecture?

---

<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: [September 16, 2021, 4:22pm UTC](https://discourse.julialang.org/t/multiple-camera-views-on-same-scene-in-makie/68274/4 "2021-09-16T16:22:03Z")

</div>

I’m not sure, that’s a question for @sdanisch
