Message Boards Message Boards

0
|
6424 Views
|
9 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Assign multiple attributes to EdgeStyle[]?

I want to give graph edges a unique color and thickness:

Graph[someGraph,
EdgeStyle->{Thickness[someValue],someColor]]

fails. Though it completes successfully with either option:

EdgeStyle->someColor OR EdgeStyle->Thickness[someValue].
Applying the options as a Directive[]:
EdgeStyle->Directive[Thickness[someValue], someColor] 

also fails. As do curly-brackets,{}; parens,(); and any combinations of them.

There are multiple options for vertices, but I cannot find comparable options for edges.

Any and all clues will be graciously accepted.

POSTED BY: Roger M Kolaks
9 Replies
Graph[someGraph,BaseStyle->{Thickness[someValue],someColor]]

would probably do the trick. I think that EdgeStyle should allow more than one input.

POSTED BY: Christian Tanguy

Dang. I was wrapping Directive[] around Rule[]. No wonder it wouldn't work. Bonehead error on my part.

Thanks to everyone for their help.

POSTED BY: Roger M Kolaks
Posted 4 years ago

An alternative

Graph[{Style[1 -> 2, Red, Thick], Style[2 -> 3, Green], Style[3 -> 1, Blue, Thin, Dashed]}]
POSTED BY: Hans Milton
Posted 4 years ago

Hi Roger,

Sorry to hear about the attic fire, hope nobody was injured.

The code you posted does not include Directive so I am not sure exactly what you tried. This works fine.

edgeList = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1};
SeedRandom[1];
colors = Table[RGBColor[rx/256, rx/256, rx/256] /. rx :> RandomInteger[{31, 255}], {Length[edgeList]}]
eStyle = Rule[edgeList[[#]], Directive[colors[[#]], Thickness[0.02]]] & /@ Range[Length[edgeList]]
Graph[edgeList, EdgeStyle -> eStyle]

enter image description here

POSTED BY: Rohit Namjoshi

Rohit, I appreciate your concern. The fire was bad but not serious and one was injured. No electricity for a week was annoying.

POSTED BY: Roger M Kolaks

I've tried something quite similar. I create the list of EdgeStyles exterior to the graph function then pass in the Table[], i.e. List of Lists.

Table[RGBColor[rx/256, rx/256, rx/256] //. 
      rx :> RandomInteger[{31, 255}], {Length[someEdgeList]}]
    eStyle = Rule[someEdgeList[[#]], %[[#]]] & /@ Range[Length[someEdgeList]]

When I create this as Directive[] it fails. The options are properly created but Mathematica ignores the added Thickness[] parameter.

I apologize for my slow response. Had an attic fire and my computer hasn't had access to electrons since Monday.

POSTED BY: Roger M Kolaks
Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 
  3 \[UndirectedEdge] 1}, 
 EdgeStyle -> {1 \[UndirectedEdge] 2 -> 
    Directive[Opacity[1], Thickness[0.02], Red], 
   2 \[UndirectedEdge] 3 -> 
    Directive[Opacity[1], Thickness[0.03], Blue], 
   3 \[UndirectedEdge] 1 -> 
    Directive[Opacity[1], Thickness[0.04], Green]}]
POSTED BY: Yaw Antoa Onyina
Posted 4 years ago

Crossposted here.

POSTED BY: Rohit Namjoshi
Posted 4 years ago

Hi Roger,

You have to use Directive to specify multiple style specifications. e.g.

Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1},
 EdgeStyle -> {
   1 \[UndirectedEdge] 2 -> Directive[Red, Thickness[0.02]],
   2 \[UndirectedEdge] 3 -> Directive[Green, Dashing[0.03], Thickness[Medium]],
   3 \[UndirectedEdge] 1 -> Directive[Blue, Dotted, Thickness[0.005]]}]

enter image description here

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract