Programmatically Get Makie Figure Size

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.

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

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

Cool - thanks. So here it is.

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

figure.scene.viewport[] should have it!

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

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

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 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).

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