# Zoom in GLMakie 3d plot then save

**URL:** <https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745>\
**Category:** General Usage\
**Tags:** plotting, glmakie\
**Created:** [August 3, 2021, 12:52pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745 "2021-08-03T12:52:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [August 3, 2021, 12:52pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/1 "2021-08-03T12:52:51Z")

</div>

Hello, I need some help to perform some simple operations on GLMakie.  
I want, say, to draw a simple torus juste like [this example](https://lazarusa.github.io/BeautifulMakie/surfWireLines/wireTori/), zoom in, and save the plot, but I could find no example on how to use Makie’s `zoom!` function.

Here is the code for plotting a torus :

```julia
using GLMakie
let
    U = LinRange(-pi, pi, 100) # 50
    V = LinRange(-pi, pi, 20)
    x1 = [cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
    y1 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
    z1 = [.5 * sin(v) for u in U, v in V]
    x2 = [1 + cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
    y2 = [.5 * sin(v) for u in U, v in V]
    z2 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
    fig = Figure(resolution =(900,600))
    ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true))
    wireframe!(ax.scene, x1,y1,z1, shading = false)
    fig[1,1] = ax
    save("zoom.png", fig)
end

```

and saving as a .png picture. I tried to zoom by adding

```julia
zoom!(ax.scene, 3)

```

to zoom by a factor 3 and it didnt work. How could I do ?  
Same question applies for translations and rotations.

PS: [this issue](https://discourse.julialang.org/t/moving-camera-then-saving-picture-in-makie/21938) seems related, but does not provide a solution on how to zoom.

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [August 19, 2021, 1:12pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/2 "2021-08-19T13:12:52Z")

</div>

In fact, any tutorial on using Makie’s `camera` would be useful, but there are not so many examples for learning…  
Anyone has something on how to zoom on a picture ? It should be simple enough, but I can’t find it on the doc and the `zoom!` method does not seem to have any effect.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 19, 2021, 4:39pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/3 "2021-08-19T16:39:58Z")

</div>

Have you tried using `scale!`:  
`scale!(ax.scene, 3, 3, 3) `

---

<div class="post-metadata">

**Author:** ![bvrb](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@bvrb](https://discourse.julialang.org/u/bvrb)\
**Post date:** [August 19, 2021, 5:16pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/4 "2021-08-19T17:16:11Z")

</div>

`zoom!(ax.scene, cameracontrols(ax.scene), 3)` followed by `update_cam!(ax.scene, cameracontrols(ax.scene))` works for me, but I believe that your version should in principle also be correct if everything was working as intended (see also [https://github.com/JuliaPlots/Makie.jl/issues/1236#issuecomment-902094122](https://github.com/JuliaPlots/Makie.jl/issues/1236#issuecomment-902094122)).

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [August 20, 2021, 8:40am UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/5 "2021-08-20T08:40:22Z")

</div>

The `scale!(ax.scene, 3,3,3)` makes no difference. When I play with the arguments. See for instance the output of the above code in the first post:

 ![zoom](https://global.discourse-cdn.com/julialang/original/3X/f/4/f48d1cc02cc738a0a4c2991bdbcb3c37fdb77b07.png)

and the output with `scale!(ax.scene, 3,3,3)` :

 ![zoom3](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed97944a7fc2db4adef69360b0abbcd98ffa5957.png)

and the output with `scale!(ax.scene, 100,100,100)` :

 ![zoom100](https://global.discourse-cdn.com/julialang/original/3X/0/b/0bc39c0271f7ed60374b8403b0883d2454b6b7cd.png)

It just removed the ticks, I don’t know why.

The solution proposed by bvrb does not work either, ie

```julia
using GLMakie
let
    U = LinRange(-pi, pi, 100) # 50
    V = LinRange(-pi, pi, 20)
    x1 = [cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
    y1 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
    z1 = [.5 * sin(v) for u in U, v in V]
    x2 = [1 + cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
    y2 = [.5 * sin(v) for u in U, v in V]
    z2 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
    fig = Figure(resolution =(900,600))
    ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true))
    wireframe!(ax.scene, x1,y1,z1, shading = false)
    zoom!(ax.scene, cameracontrols(ax.scene), 3)
    update_cam!(ax.scene, cameracontrols(ax.scene))
    fig[1,1] = ax
    save("zoom_alt.png", fig)
end

```

ends with the same picture.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 20, 2021, 10:34am UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/6 "2021-08-20T10:34:44Z")

</div>

Please [check solution in this other post](https://discourse.julialang.org/t/saving-makie-plot-as-is-on-the-screen/24276/2), it works (_GLMakie v0.4.4_):

 ![GLMakie_Wireframe_Torus_zoom](https://global.discourse-cdn.com/julialang/original/3X/4/f/4fa3d9afdcfb3676616c29409205b4db56598b57.jpeg)

---

<div class="post-metadata">

**Author:** ![bvrb](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@bvrb](https://discourse.julialang.org/u/bvrb)\
**Post date:** [August 22, 2021, 3:44pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/7 "2021-08-22T15:44:55Z")

</div>

Indeed, there are two separate issues here - the zooming itself, and then saving the picture. I had only tried it directly in the REPL.

Just for completeness sake, combining the code you quoted and what is proposed in [rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)’s link:

```julia
using GLMakie

U = LinRange(-pi, pi, 100) # 50
V = LinRange(-pi, pi, 20)
x1 = [cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
y1 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
z1 = [.5 * sin(v) for u in U, v in V]
x2 = [1 + cos(u) + .5 * cos(u) * cos(v) for u in U, v in V]
y2 = [.5 * sin(v) for u in U, v in V]
z2 = [sin(u) + .5 * sin(u) * cos(v) for u in U, v in V]
fig = Figure(resolution =(900,600))
ax = LScene(fig, scenekw = (camera = cam3d!, show_axis = true))
wireframe!(ax.scene, x1,y1,z1, shading = false)
zoom!(ax.scene, cameracontrols(ax.scene), 3)
update_cam!(ax.scene, cameracontrols(ax.scene))
fig[1,1] = ax
ax.scene.center = false
save("zoom_alt.png", fig)

```

This, for me (with GLMakie v0.4.4), results in a zoomed out picture:

 ![zoom_alt](https://global.discourse-cdn.com/julialang/original/3X/8/8/88b9d7039152d5e57673038da7b7a73aedf30e88.png)

Alternatively, `zoom!(ax.scene, cameracontrols(ax.scene), 1/3)` will zoom in instead:

 ![zoom_alt_2](https://global.discourse-cdn.com/julialang/original/3X/2/2/22d15865e114b6229dfe679bb1f11c10fc381137.jpeg)

---

<div class="post-metadata">

**Author:** ![sim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sim/32/22207_2.png) [@sim](https://discourse.julialang.org/u/sim)\
**Post date:** [August 23, 2021, 8:10am UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/8 "2021-08-23T08:10:32Z")

</div>

@bvrb It works perfectly. Thank you !

---

<div class="post-metadata">

**Author:** ![Kang\_Pyo\_So](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kang_pyo_so/32/26391_2.png) [@Kang\_Pyo\_So](https://discourse.julialang.org/u/Kang_Pyo_So)\
**Post date:** [October 6, 2021, 10:06am UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/9 "2021-10-06T10:06:41Z")

</div>

> [@bvrb](#):
>
> v0.4.4

current version is [  
v0.3.4Latest  
on Jun 8  
 ](https://github.com/JuliaPlots/GLMakie.jl/releases/tag/v0.3.4)

mine shows an error in zoom  
" **MethodError: no method matching zoom!(::Scene, ::Camera3D, ::Int64)**  
something wrong with me

---

<div class="post-metadata">

**Author:** ![bvrb](https://avatars.discourse-cdn.com/v4/letter/b/76d3ee/32.png) [@bvrb](https://discourse.julialang.org/u/bvrb)\
**Post date:** [October 7, 2021, 4:03pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/10 "2021-10-07T16:03:29Z")

</div>

That repository you linked is outdated, citing from the `README.md`:

> **INFO: This repository is deprecated**
> 
> GLMakie has been moved into the monorepo at [Makie.jl](https://github.com/JuliaPlots/Makie.jl). The latest version can be determined by checking the Project.toml in the GLMakie subdirectory. `add GLMakie` will now install from the monorepo for GLMakie versions above 0.3.4.

If we check the [`Project.toml`](https://github.com/JuliaPlots/Makie.jl/blob/master/GLMakie/Project.toml) file in the GLMakie subdirectory, the newest version now is actually `0.4.6`.

What is the output of `pkg> st GLMakie`? Have you tried updating it via `pkg> up GLMakie`? If that doesn’t work, you could also try removing it, and then adding it again, I am not sure if it gets picked up automatically if the repository moves and you still have the old version installed. Alternatively, if you `add GLMakie` in a fresh environment it should definitely work.

(By the way, the bug mentioned in in the OP [has already been fixed](https://github.com/JuliaPlots/Makie.jl/pull/1247) in the newest release, so you should now be able to just do `zoom!(ax.scene, 3)`, no workaround necessary anymore.)

---

<div class="post-metadata">

**Author:** ![rvezy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rvezy/32/17435_2.png) [@rvezy](https://discourse.julialang.org/u/rvezy)\
**Post date:** [February 9, 2024, 5:38pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/11 "2024-02-09T17:38:54Z")

</div>

Sorry to re-open this discussion, but GLMakie resets my zoom when saving too. I’m on GLMakie v0.9.8, and there is no field `center` in the scene anymore (`ax.scene.center`). How should I do?

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [February 9, 2024, 9:35pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/12 "2024-02-09T21:35:23Z")

</div>

`save(...; update=false)`

---

<div class="post-metadata">

**Author:** ![barnett567](https://avatars.discourse-cdn.com/v4/letter/b/e0b2c6/32.png) [@barnett567](https://discourse.julialang.org/u/barnett567)\
**Post date:** [February 21, 2024, 8:04pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/13 "2024-02-21T20:04:51Z")

</div>

Thank-you. I just wasted an hour trying to get the zoom to stick when saving. Finally found this. It is still a bug that the zoom is undone at the save stage (I’m on CairoMakie v0.11.8). I hope this workaround can be added on the Makie Troubleshooting page. Great package!

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [May 6, 2024, 2:56pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/14 "2024-05-06T14:56:28Z")

</div>

Somehow I can still not figure out how to make this work.

Looking at this example

```julia
using GLMakie
begin
    fig = Figure() 
    ax = LScene(fig[1,1])

    surface!([-8,-8,8,8],[-8,8,-8,8],[0,0,0,0])
    meshscatter!([1],[1],[1], markersize = 1)

    zoom!(ax.scene, cameracontrols(ax.scene), 0.1)
    #zoom!(ax.scene, cameracontrols(ax.scene), 2.0)
    update_cam!(ax.scene, cameracontrols(ax.scene))
    
    fig
end

```

No matter which of the `zoom!` lines I call, it makes no difference in the displayed plot.

It seems that at `disp(fig)` it adjusts the camera to fit the scene. Is there a way to deactivate that?

(Sorry if the question is already answered, I tried to look for it for quite a while but wasn’t successful.)

Packages in my env:

```julia
  [a9b6321e] Atomix v0.1.0
  [052768ef] CUDA v5.3.3
  [e9467ef8] GLMakie v0.9.10
  [5c1252a2] GeometryBasics v0.4.11
  [63c18a36] KernelAbstractions v0.9.18
  [90137ffa] StaticArrays v1.9.3

```

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [May 10, 2024, 1:15pm UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/15 "2024-05-10T13:15:24Z")

</div>

`display(fig, update=false)` and `save(fig, update=false)` should work.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [June 16, 2024, 7:36am UTC](https://discourse.julialang.org/t/zoom-in-glmakie-3d-plot-then-save/65745/16 "2024-06-16T07:36:02Z")

</div>

Thanks! Also `record(..., update=false)` works, which is what I needed in my setup.
