JuliaGraphs / GraphPlot.jl

Graph visualization for Julia.
http://JuliaGraphs.github.io/GraphPlot.jl/
Other
200 stars 62 forks source link

Bad displays #190

Closed Lecrapouille closed 2 months ago

Lecrapouille commented 1 year ago

Hi ! Again to disturb you. Here is my matrix:

A = [3 7; 2 4]

Which corresponds to the expected network. Expected

The following code

G = SimpleWeightedDiGraph(A)
gplot(G, nodelabel=1:nv(G), edgelabel=B)

gives me: Obtained1

Issues are:

Based on https://github.com/JuliaGraphs/GraphPlot.jl/issues/160 The following code

gplot(G, nodelabel=1:nv(G), edgelabel=B, linetype="curve")

gives me: Obtained2

There are:

I dunno if https://github.com/JuliaGraphs/GraphPlot.jl/pull/186 will fix this simple graph.

hdavid16 commented 1 year ago

Thanks for pointing these out. #186 will allow you to make a plot like the first one with straight edges for the non-self loops, and curved edges for the self loops. The cut out can be fixed in the PR as well because you can add margins to ensure the curved edges are fully shown.

However, the edge labels on curved edges don't work as expected. Thanks for pointing this out. I'll see if we can get curved edge labels to work.

hdavid16 commented 1 year ago

@Lecrapouille,

I just stumbled upon GraphMakie.jl, which seems to be more actively developed and has better support for curved edges. Here is your example in GraphMakie

using Graphs, GraphMakie, CairoMakie

B = [3 7; 2 4]
g = SimpleDiGraph(B)
graphplot(g,
    layout = g -> [Point(-1,0), Point(1,0)],
    nlabels = string.("node ",1:nv(g)),
    elabels = string.([B[src(e),dst(e)] for e in edges(g)]), 
    elabels_rotation=0, 
    arrow_shift=0.99, 
    curve_distance = 0.1, 
    selfedge_size=1,
    selfedge_width=pi/9
)

This will produce the plot:

image

You can of course do much more customization on the appearance if you want. Now the edge labels will be in the right place.

Lecrapouille commented 1 year ago

@hdavid16 Thanks you I'll give a try.

hdavid16 commented 1 year ago

@Lecrapouille, I've added a commit to the PR #186 that will produce the following. This should fix the bug on the edge labels for curved edges.

B = [3 7; 2 4]
g = SimpleDiGraph(B)
gplot(g, [-1.,1.], [0.,0.],
    nodelabel=1:nv(g),
    edgelabel=B,
    linetype="curve",
    EDGELINEWIDTH=1,
    outangle=-pi/3,
    pad=5mm
)
image