Message Boards Message Boards

Creating a new GraphStyle—possible?

Posted 7 years ago

Hello everyone,

I found this feature example page, which unfortunately seems to be empty in all versions I have installed.

https://reference.wolfram.com/language/example/CreateYourOwnGraphStyle.html

I was wondering if this meant that it was possible to create a custom GraphStyle that can then be easily re-used.

I know that I could use an explicit option list with {VertexStyle -> ..., EdgeStyle -> ..., ...}. After finding this example page, I simply became curious if there was a builtin feature to give a set of styles a name.

POSTED BY: Szabolcs Horvát
2 Replies

Thanks for the clarifications Vitaliy!

I was hopeful for a custom graph style because it would allow things like this:

Graph[{1 <-> 2}, GraphStyle -> "DiagramGreen", 
   VertexStyle -> {1 -> Yellow}]

Mathematica graphics

This does not work because it duplicates the VertexStyle option:

style = {VertexStyle -> Green, VertexSize -> Medium};

Graph[{1 <-> 2}, style, VertexStyle -> {1 -> Yellow}]

Mathematica graphics

However, there are numerous workarounds:

During construction:

Graph[{Style[1, Yellow], 2}, {1 <-> 2}, style]

Mathematica graphics

In[4]:= PropertyValue[%, VertexStyle]
Out[4]= {RGBColor[0, 1, 0], 1 -> {RGBColor[1, 1, 0]}}

Or after construction:

HighlightGraph[Graph[{1 <-> 2}, style], {Style[1, Yellow]}]

Mathematica graphics

POSTED BY: Szabolcs Horvát

Thank you for reporting this. I think that page meant regular options. No custom GraphStyle. I usually resort to something like below. I hope people will realize a neat trick which will become obvious if you remove AspectRatio->1. This is a method to keep vertex size scaled relevant to 'Graphics` size and not stretched. Some may find also THIS useful.

style={
    DirectedEdges->True,
    GraphStyle->"Prototype",
    VertexLabels->Placed["Name",Center],
    GraphLayout->"RadialEmbedding",
    VertexSize->Scaled[.07],
    AspectRatio->1
};

TreeGraph[RandomInteger[#] <-> # + 1 & /@ Range[0, 25], style]

enter image description here

POSTED BY: Vitaliy Kaurov
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