Setting size (resolution) of makie plot when plotting?

I want to change the size of a plot I am making in Makie. I try:

graphplot(mygraph,resolution=(500,500))

but get an error:

ERROR: setting resolution for scene via plot attribute not supported anymore

Is there some other command to use to change the plot’s size instead of resolution?

If it is just one plot element in a figure then increasing the resolution increases the plot’s size, e.g. you can use

using CairoMakie
CairoMakie.activate!()

f = Figure(resolution=(500,500))
ax = Axis(f[1,1])
lines!(ax, 1:5, 1:5)

save("mwe.png", f)

If you want to create a figure with multiple plot elements, where the figure’s space is not equally partitioned between the plots, then you will have to dive into GridLayouts. Here is a link to a tutorial for this: Layout Tutorial

1 Like

Sorry, I do not really understand. So I have only used plots where I would do plot(..., size=(400,400)). However, there is no similar approach in Makie?

Sorry, but I am not so familiar with Plots.jl.

When I try running a MWE from the Plots docs, e.g. this one Introduction · Plots, and I add resolution=(500,500) in, I don’t see anything changing.

Could you maybe provide an example figure to illustrate of what is not working and/or what you want to achieve?

1 Like

Makie figures can contain multiple plots, and resolution is set at the figure level rather than the plot level. Plotting with the simplified interface plot(...) implicitly creates a figure container to plot into, but you can set the resolution of that figure (as well as other figure or axis attributes) with the figure (and axis) keyword arguments. This should work: graphplot(mygraph; figure=(resolution=(500,500),))

2 Likes

The differences between Plots.jl and Makie.jl can sometimes be a bit confusing, especially because both use a function called plot. But Plots’s plot creates abstract objects which are descriptions of figures with possibly multiple subplots arranged in layouts. When you plot! into those, you just add to the description, which is at the end converted into a complete visualization in whatever backend you have activated.

In Makie, there’s Figure (a Scene with a GridLayout), which can contain stuff like Axis, Colorbar, Legend, etc, and all of these objects are built up out of Scenes which contain “plot primitives” such as Lines, Scatter, Heatmap, etc. All plotting functions at their core create such “plot primitives”, but, as a convenience, the containers for these are created as well in the default case. Usually, that’s a Figure with an Axis inside. So heatmap(...) makes a Heatmap plot object, which is stored inside an Axis, which is placed inside a Figure. To pass keyword arguments to the Axis, you can do heatmap(...; axis = (; title = ... and for the Figure you do heatmap(...; figure = (; resolution = ....

Remember that in Plots.jl, you don’t control all these different objects, you just make an abstract “plot description”, therefore all keywords are top-level keywords, and Plots.jl sorts out which relate to what would be the Figure in Makie, or the Axis, or the Plot. But in Makie, it’s completely separated, that’s why all Figure keywords have to be sent in via the special figure keyword. For example, in principle some plot might have a title attribute, and this way you could set that plus the axis title via some_plot(...; title = "Plot title", axis = (; title = "Axis title"....

If, in Makie, you go the mutation route, the plotting function loses its ability to pass Figure and Axis information on, because those have already been created beforehand:

f = Figure(resolution = ...)
ax = Axis(f[1, 1], title = ...)
heatmap!(ax, ...; # no figure or axis keyword allowed here, those already exist
1 Like

Thanks for the throughout explanation of what was going on, that was really useful!.