GraphPlot.jl icon indicating copy to clipboard operation
GraphPlot.jl copied to clipboard

Plotting mixed graphs

Open bvilmann opened this issue 5 years ago • 2 comments

Hi!

I am fairly new to Julia but I am amazed and I started using GraphPlot. I have an idea for improvement and I would also really like to contribute with this via a PR.

However, since I am quite new to github also, I want to discuss my idea with you before going into action (and start learning how to use github properly regarding PRs meanwhile).

Mixed graphs: It could be nice if GraphPlot could do mixed graphs too.

I think a simple and fine implementation could be via an individual mapping of the edges. In a lot of plotting cases, you have already done your mapping.

The origin of this issue, e.g., was that I wanted to plot the optimization of a transport model. I had all the flows in the graph mapped to an edge color corresponding to a flow/capacity-ratio: transport_model1

Here, it could just be nice to write something like: gplot(g,arrowlengthfrac=[abs(flow[i]) > 0 ? 0.1 : 0 for i in 1:num_of_edges])

And thereby avoiding the arrows of all the grey edges, which just disturbs the image.

I have looked into plot.jl and lines.jl, and it seems doable without too much effort and without mess up the control flow of the code.

Perspectives: I have the impression that GraphPlot is built around LightGraphs and MixedGraph() is not yet a method. But preparing for a graph tool, in the case of a future MixedGraph() method, could be nice either way.

What do you think? Do you find any immediate issues or should I try to start making it work?

All the best, Benjamin

bvilmann avatar Dec 09 '20 13:12 bvilmann

Great idea. We basically need to support arrowlengthfrac to be a vector of reals, rather than a Real. Would you still be interested in taking a stab at it?

hdavid16 avatar Jul 27 '22 16:07 hdavid16

@bvilmann you can accomplish this with GraphMakie.jl by setting the arrow size to 0 for those edges where you don't want an arrow:

using Graphs, GraphMakie, GLMakie

g = cycle_graph(4)
graphplot(g, arrow_size=[20,0,20,0], arrow_shift=:end)

image

hdavid16 avatar Apr 03 '23 17:04 hdavid16