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

Multiple Edge Colors

Open jwassmer opened this issue 3 years ago • 5 comments

An option to have multiple edge colors would be awesome. I would like to able to do something like this:

using Plots, GraphRecipes, Colors
g = [0 1 1;
     1 0 1;
     1 1 0]
graphplot(g,
          x=[0,-1/tan(π/3),1/tan(π/3)], y=[1,0,0],
          nodeshape=:circle, nodesize=1.1,
          axis_buffer=0.6,
          curves=false,
          edgecolor=[colorant"#389826",colorant"#CB3C33",colorant"#9558B2"],
          linewidth=10)

But at the moment you can only input single colors to edgecolor. Is there a workaround to do this?

jwassmer avatar Oct 12 '21 11:10 jwassmer

There's a pretty terrible hack, but if anyone is desperate:

  1. pick a method that's invariant to edge structure and non-random, e.g. :circular.
  2. plot your graph with the first colour you want for your edges.
  3. plot the subgraph of your original graph again with graphplot!() such that the only included edges are those that should be a different colour.

This should work. You can also show random walks over graphs using a DiGraph in your second plot call, e.g.

download-1

This is a little messy in places, but I think that could be cleaned up by setting curves to false or messing around with edge width.

JasonPekos avatar Jul 01 '22 20:07 JasonPekos

followup: if you want this specific feature, you might be better off using GraphMakie as of Jul 2022. It seems a little more feature complete here.

JasonPekos avatar Jul 04 '22 19:07 JasonPekos

Hi, I'm also interested in setting different colors to edges and to node borders. I found here that at some point it was possible to do it. Setting different edges colors still work with edge_z (eg, G is a SimpleWeightedDiGraph, you can set edge_z = (s,d,w) -> G.weights[d,s]). However, it's not possible to set different border colors for the nodes anymore. I'll open a new issue for this.

gabrevaya avatar Nov 08 '22 18:11 gabrevaya

I would also make use of this feature. Am using a simple DiGraph to display causal models. The desire is to color code paths as wether they represent a dependency and whether or not they are blocked. The logic is already coded but am stuck not being able to set the color of edges individually. edgecolor argument does not accept vector or dict.

bobaronoff avatar Nov 14 '22 21:11 bobaronoff

I may have posted too soon - my apologies. It is possible apply a multi-color scheme to edges. The solution seems to be to supply edgecolor with a dictionary and NOT a vector. The key of the dict is a tuple (s,d) that corresponds the edge designation. There needs to be a key for every edge. The value of the key is the color of that edge. I used Symbol values (i.e. :gray0, :red, :green, etc). This seems to be working. If this is correct, perhaps this info could be added to documentation.

bobaronoff avatar Nov 15 '22 01:11 bobaronoff