0

How do I set properties of graphs permanently? Is there any way?

For example VertexLabels -> "Name".

I would like to see labels, always when I open a new notebook and I run the codes: CycleGraph[5], WheelGraph[6], MyCommand[...], Graph[...], etc. I.e.: Object with Head=Graph or a function which return such an object should display labels.

I do not see any labels here (the below Jens' answer): enter image description here

ZYX
  • 561
  • 2
  • 8
  • Do you mean something like this? SetOptions[Graph, VertexLabels -> {3 -> "Name"}] followed by any Graph: you'll get the same label every time, unless you override it. – Jens May 07 '16 at 22:02
  • No. I would like to see labels, when I open a new notebook and I run for example CycleGraph[5]. – ZYX May 07 '16 at 22:19

1 Answers1

5

As I mentioned in the comment, what you probably need is SetOptions. For example,

SetOptions[CycleGraph, VertexLabels -> "Name"];

CycleGraph[5]

To make this work automatically, either add it to init.m, or (more portable) make the first cell above an InitializationCell.

Of course, you can do the same SetOptions for other commands too, not just CycleGraph.

Jens
  • 97,245
  • 7
  • 213
  • 499
  • This method doesn't work for an arbitrary graph!!!! – ZYX May 10 '16 at 19:49
  • @ZYX the last paragraph tells you what to do. – Yves Klett May 11 '16 at 04:38
  • This doesn't work for a graph, but for a command. So it doesn't work, if I write a new command or use CycleGraph[.], WhellGraph etc. (with SetOptions[Graph, VertexLabels -> "Name"];). It is useless - add to init.m all build-in and new functions, which return a graph. – ZYX May 14 '16 at 20:41
  • 1
    @ZYX I think it's a bit like Graphics and Plot. Graphics has Axes -> False, but the graphics produced by Plot has axes, because the more specific command Plot overrides the defaults for Graphics. Similarly, CyclicGraph overrides Graph. – Michael E2 May 14 '16 at 22:24