Makie: figure resolution in inches

How do I create a figure whose size is given in inches instead of pixels?

fig = Figure(res = ?)

I’ve searched the Makie.jl docs but I really didn’t find out how. Search keywords resolution and inches did not yield useful results.

I’ll add a section about this to the docs soon.

1 Like

I have also been looking for a way to do this naturally, and have been meaning to ask a related question for a little while now.

To answer the original question, I found the that there is an assumed dpi of 72, so specifying your resolution as 72 * size works. Maybe this is what @jules is adding to the docs?

However, this means that, on my monitor, the figure will display as much smaller than the size I want (my laptop monitor dpi > 72). But, when saving a figure, I get what I want.

Alternatively, one could specify a larger resolution for the initial image, and then scale down when saving. However, this does not play nicely with theming (I have been using the excellent theming capabilities of MakieLayout recently). If I want size 14 font, linewidth of 2, those stay the same size on the screen when I make a larger image, and become relatively small vs. the rest of the plot (and become too small when the image is scaled down for saving). I could go through all of my themes (I have some for images that will go in powerpoints, some for fullwidth / halfwidth in manuscripts, etc.) and prescale everything so that I could then specify a larger resolution for viewing and resize down for saving… but this seems excessive and error-prone (the theme has to know the dpi I will choose for display). It also doesn’t translate well when going from my laptop to my desktop.

I am not sure what the best solution to this is. I understand why specifying everything in pixels is better for many work flows, but for me the specification in PyPlot (or even MATLAB) makes more sense. I give an image size in a physical unit, and can choose a dpi for display and a dpi for saving. The size of text and linewidths, etc. is tied to the physical size, so they don’t change when I change the dpi. Is there any chance of supporting this type of work flow? Or is it already there and I am just missing it?


1 Like

Heh to be a bit honest I was originally asking because I wanted a high resolution for the saved output figures. I then realized I only need to give px_per_unit = 4 at the save function, and use some standard e.g. 1000x500 pixes figure size!

Glad you found your solution!

I mostly use CairoMakie for vector graphics, so the actual resolution doesn’t matter to me much, just the relative sizing of everything.

Relatedly, I noticed this morning that 7/20 posts on the main page referenced Makie in the title. Congrats! It appears (to me at least) that adoption is increasing.

But I also imagine that means developer time is stretched. I would be willing to help work on a solution (for my issue… which I also just saw was brought up in No docs for figure attributes in Makie, but I don’t know the code base (or development roadmap) or really how I would get started. There is no point in proposing a solution wildly incompatible with the Makie internals. What is the best way to contribute to designing a solution?

1 Like

Can you describe exactly what behavior you want? Vector or bitmap, where do you display, what size do you expect, etc.

The unitless approach that maps to pixels in GLMakie and WGLMakie is because GLMakie came first, and it still doesn’t have any super-resolution ability like CairoMakie does. But in CairoMakie, you should be able to easily scale up any plot with pt_per_unit and px_per_unit.

Here’s a preview of what I was writing in case it helps Exporting a Figure with physical dimensions

1 Like

Sure, I’ll try to describe it as cleanly as I can without assuming implementation detail (as I can think of a few different approaches).

I would like to simultaneously do the following three things

  1. Specify a figure size in units that related to the other plotable size quantities (line widths, text font size, etc.). This makes theming consistent.
  2. Display the figure at a desired screen size
  3. Save a figure at a desired physical size.

Currently it is easy to do 2 of the 3, but not all three.

The example in the link for “Vector Graphics” shows my current work flow, and achieves 1 & 3, but not 2 - my monitor has a pixel resolution > 72 pixels/inch, so when developing a figure and working interactively it is quite small, to the point where it is hard to read small text (such as ticks).

As I said earlier, I could scale everything up, but that requires scaling up every theme I have as well. If I go to a different monitor with a different pixel density things will again look different.

It would be great to have consistent behavior for vectors and bitmaps, but that might not be possible.

One solution might be to be able to specify a size and dpi OR a resolution, but not both. Alternatively the figure could take a display scaling argument (similar to how you can scale on save). Most natural to me is to specify a physical size and dpi, but that might be the most breaking.

1 Like