How to customize figure size (and other things) with using GraphMakie?

I have the following code to draw a directed graph with edge weights.

## Load the packages
using Random
using CairoMakie
using GraphMakie
using Graphs
using LaTeXStrings
using Colors

## Create a random directed graph
vnum = 4
enum = 6
ilabels = string.('a':'z')[1:vnum]
seed = 1234
g = erdos_renyi(4, 6, is_directed = true, seed = seed)
Random.seed!(seed)
elabels = LaTeXString.(string.(rand(1:10, enum)))

## Plot the data
font_size = 32
fig, ax, p = graphplot(
    g;
    ilabels = ilabels,
    ilabels_fontsize = font_size,
    elabels = elabels,
    elabels_fontsize = font_size,
    node_color = :orange,
    edge_color = :gray,
    edge_width = 4,
    node_strokewidth = 4,
    arrow_shift = :end,
    arrow_size = 40,
);
hidedecorations!(ax);
hidespines!(ax);
colsize!(fig.layout, 1, Aspect(1, 1.0));
resize_to_layout!(fig);
fig

My question is how can I change the figure size? I have tried to add size parameter to graphplot without success.

Also, as you can see, the nodes in the picture gets cut off when they are too large. Is there any way to avoid this?

Thank you!

If graphplot behaves similar to other Makie plotting function, then you need to do

fig, ax, p = graphplot(
    g;
    figure = (; size=(200,200),
    # other kwargs
)

to “pass” the size kwarg through to the underlying Figure.

2 Likes

This works! :smiley:

Any idea how I may extend the cut off position a bit?

After posting on Github, I got a reply: Nodes get cut-off when ilabels_fontsize is set to large number. · Issue #196 · MakieOrg/GraphMakie.jl · GitHub

Have you had success using the linked workaround in discourse or the solution by mschauer?
If your image is fairly static and it is acceptable to find suitable limits by hand, you can use the Axis=(; limits…) keyword of the plot function to set manual exits limits from within a single plot command.

1 Like

I haven’t tried the linked workaround since it looks a bit complicated. But the solution by mschauer works! Thanks.