# Programmatically Get Makie Figure Size

**URL:** https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893
**Category:** Visualization
**Tags:** makie, cairomakie
**Created:** [April 13, 2024, 12:33am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893 "2024-04-13T00:33:36Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [April 13, 2024, 12:33am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/1 "2024-04-13T00:33:36Z")

</div>

Hello,

Is it possible to programmatically get the `width` and `height` of a figure in Makie assuming you did not explicitly specify them in the call to `Figure()`?

I’m curious because they would be helpful for placing a zoom box (`BBox`) on the figure. I could specify the location using normalized coordinates (between 0 and 1) and then scale them by the width or height of the figure.

I was able to find the fields within the figure object but I can’t seem to extract the number from them. My expectation is they would be specified based on some default value in units of pixels. That might be wrong, just my initial expectation.

```julia
fig.layout.width[] # Auto(true, 1.0f0)
fig.layout.height[] # Auto(true, 1.0f0)

```

---

<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: [April 13, 2024, 1:43am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/2 "2024-04-13T01:43:06Z")

</div>

`fig.scene.viewport` is the observable that holds the main scene rectangle

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [April 13, 2024, 2:34am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/3 "2024-04-13T02:34:40Z")

</div>

Cool - thanks. So here it is.

```julia
fig.scene.viewport[].widths # two element vector holding width and height in pixels

```

---

<div class="post-metadata">

### Author: ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)
#### Post date: [April 13, 2024, 3:02am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/4 "2024-04-13T03:02:26Z")

</div>

`figure.scene.viewport[]` should have it!

edit: whoops, replied by email and didn’t see the original thread 😃

---

<div class="post-metadata">

### Author: ![jerlich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jerlich/32/5205_2.png) [@jerlich](https://discourse.julialang.org/u/jerlich)
#### Post date: [October 18, 2024, 8:37pm UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/5 "2024-10-18T20:37:28Z")

</div>

What about programatically setting the figure size and width after creation?

---

<div class="post-metadata">

### Author: ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)
#### Post date: [October 19, 2024, 12:08am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/6 "2024-10-19T00:08:41Z")

</div>

I never find the need to do it. I typically have a theme with a standard size or I set it explicitly in the `Figure()` constructor. Afterwards I will also usually call `resize_to_layout!(fig)`. Also, I found this [page](https://docs.makie.org/stable/explanations/figure#Figure-size-and-units) **very helpful** in getting figures printed out the way I wanted. Note that if you do bitmapped images like `.png` and are using them in latex doc you might need to scale them for them to appear the correct size (this wasn’t obvious to me until I tried to include them without any scaling). For example when I insert images I use something like this in latex docs: `\includegraphics[width=5in,height=4in]{my_fig}` (but thats after I followed the guidance in the above link on getting consistent figure sizes).

---

<div class="post-metadata">

### Author: ![jerlich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jerlich/32/5205_2.png) [@jerlich](https://discourse.julialang.org/u/jerlich)
#### Post date: [October 19, 2024, 10:54am UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/7 "2024-10-19T10:54:23Z")

</div>

Ya… I agree, it’s not really needed.

---

<div class="post-metadata">

### Author: ![bjarthur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bjarthur/32/9638_2.png) [@bjarthur](https://discourse.julialang.org/u/bjarthur)
#### Post date: [January 8, 2025, 2:14pm UTC](https://discourse.julialang.org/t/programmatically-get-makie-figure-size/112893/8 "2025-01-08T14:14:56Z")

</div>

> [@jerlich](#):
>
> What about programatically setting the figure size and width after creation?

`resize!(fig, width, height)`
