# GraphMakie distance between nodes

**URL:** <https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [April 2, 2025, 12:16pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624 "2025-04-02T12:16:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [April 2, 2025, 12:16pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624/1 "2025-04-02T12:16:08Z")

</div>

Is there a way to adjust the distance between nodes? I have a simple graph like this that works:

```julia
begin
	g2 = cycle_digraph(3)
	fg=Figure(size=(800,800))
	axg=Axis(fg[1,1])
	GraphMakie.graphplot!(axg,g2;
	                     ilabels=[L"\,\,\,\mathrm{R}_i\,\,\,", L"\mathrm{R}_a", L"\mathrm{R}_r"], arrow_shift=:end,node_size=60,curve_distance=-.5, curve_distance_usage=true)
	hidedecorations!(axg); hidespines!(axg); 
	fg
end

```

I understand that I can manually specify node positions. It would be nice if I could specify some parameter to bring them closer (i.e. decrease edge lengths) rather than calculating the positions by hand each time. Is this possible?

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [April 2, 2025, 12:29pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624/2 "2025-04-02T12:29:21Z")

</div>

The layout of the nodes in GraphMakie is determined by the layouts defined in [NetworkLayouts.jl](https://juliagraphs.org/NetworkLayout.jl/stable). I think you could play around with different layouts, the [Stress layout](https://juliagraphs.org/NetworkLayout.jl/stable/#Stress-Majorization) for example supports a weights matrix which should influence the results.  
Depending on your usecase you might want to look at the `pin` property available in several different layouts (e.g. Stress and Spring), which allows you to place a few vertices manually, while the layout will automatically place all the others.

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [April 2, 2025, 12:36pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624/3 "2025-04-02T12:36:31Z")

</div>

Also, layouts are just functions which take a graph and return a list of positions. So sometimes it is usefull to just define your own layout which does some “postprocessing”. I.e.:

```julia
# define layout, which allways cuts the distance between nodes 7 and 8 in half
function mylayout(g)
    pos = NetworkLayout.stress(g) # get the initial layout based on your favorite layout algo
    # move vertices 7 and 8 closer together
    path = pos[8] - pos[7]
    pos[7] = pos[7] + 0.25 *path
    pos[8] = pos[8] - 0.25 *path
    return pos
end

graphplot(g; layout=mylayout)

```

---

<div class="post-metadata">

**Author:** ![contejuz](https://avatars.discourse-cdn.com/v4/letter/c/e79b87/32.png) [@contejuz](https://discourse.julialang.org/u/contejuz)\
**Post date:** [April 2, 2025, 6:15pm UTC](https://discourse.julialang.org/t/graphmakie-distance-between-nodes/127624/4 "2025-04-02T18:15:11Z")

</div>

Great, thank you! I’ll do some research into the various layouts.
