3
$\begingroup$

I'm looking to export a small graph in the documentation to a vector file, such that it's appearance doesn't change.

Originally, I wanted to use the following example from the doc page of AdjacencyList[] with a single tweak to the vertex label color. Why? Because I liked the spacing it had on its labels, as you can see:

enter image description here

So I evaluated the cell, hoping to then add options programmatically, but simply evaluating it made the nice vertex formatting go away:

enter image description here

Ok, so I stepped back and just tried to export it as-is to any (vector) format at all. First, I tried converting it to graphics with the right click menu, no luck:

enter image description here

Then I tried saving to a variety file types, but again nothing I exported looked anything like the original graph, for example:

enter image description here

Interestingly, I found out that Postscript isn't even supported (it is an option and is supposed to be):

enter image description here

Finally, I tried the file menu option for saving a selection, but this does nothing or fails silently!

enter image description here

I'm at a loss that such a simple thing is evading me.

$\endgroup$
  • $\begingroup$ I think a better title would be less about the export and more about the formatting. In this case the Export is seemingly distinct from the problem, even though it is why you want the problem solved. $\endgroup$ – b3m2a1 Jan 21 '18 at 5:34
2
$\begingroup$

The easiest way to use vertex names as the image of the vertices is

CompleteGraph[5, VertexShapeFunction -> "Name"]

enter image description here

As you can see, the spacing is not great. The edges overlap with the vertices. When this happens, the first thing you should try is

CompleteGraph[5, VertexShapeFunction -> "Name", 
 PerformanceGoal -> "Quality"]

enter image description here

This almost always fixes this problem. The most common use case is directed graphs where part of the arrowhead overlaps with the vertex. But I also use it in this specific situation.

If you want to tweak the spacing further, use VertexSize.

CompleteGraph[5, VertexShapeFunction -> "Name", 
 PerformanceGoal -> "Quality", VertexSize -> Large]

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Do you know of a simple option to set the edges to use CapForm? $\endgroup$ – M.R. Jan 21 '18 at 19:12
  • $\begingroup$ @M.R. CompleteGraph[5, VertexShapeFunction -> "Name", PerformanceGoal -> "Quality", EdgeStyle -> Directive[AbsoluteThickness[5], CapForm["Round"]], VertexSize -> 0.2] $\endgroup$ – Szabolcs Jan 21 '18 at 20:04
  • $\begingroup$ Ah, I see the PerformanceGoal activates the CapForm. Thanks. $\endgroup$ – M.R. Jan 21 '18 at 20:18
  • $\begingroup$ One more thing - how to make the endpoints equidistant from the glyph? Perhaps that's too big a question for a comment... $\endgroup$ – M.R. Jan 21 '18 at 20:24
  • $\begingroup$ @M.R. If you want it equidistant from the center of each glyph (not their bounding box), then you can use something similar to CompleteGraph[5, VertexShapeFunction -> None, PerformanceGoal -> "Quality", VertexLabels -> Placed["Name", Center], VertexLabelStyle -> Large, EdgeStyle -> Directive[AbsoluteThickness[5], CapForm["Round"]], VertexSize -> 0.2]. A bonus is that you can control the glyph style using VertexLabelStyle. $\endgroup$ – Szabolcs Jan 21 '18 at 20:30
4
$\begingroup$

Graph formatting has changed recently. The Box form it used to have is no longer the one it has.

So the easiest thing to do is probably just to regenerate your graph with formatting:

CompleteGraph[5,
 VertexShape -> Table[n -> Graphics[Inset[Style[n, Black]]], {n, 5}],
 VertexSize -> .25,
 ImageSize -> 100
 ]

ggg

Szabolcs would know better than I, though, as to how to get that type of white-space without such fine-tuning

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks! How did you find this out? $\endgroup$ – M.R. Jan 21 '18 at 5:34
  • 1
    $\begingroup$ The box formatting thing? I've just looked at a bunch of the box structures when I tried to implement a click-and-drag format-able graph. Noticed that most of them in the documentation notebooks are different from the box structures that are spit out now. $\endgroup$ – b3m2a1 Jan 21 '18 at 5:35
  • $\begingroup$ With this new syntax, is there an easy way to get the edge lines to have CapForm["Round"], without extracting them and using EdgeShapeFunction? $\endgroup$ – M.R. Jan 21 '18 at 5:47
  • 1
    $\begingroup$ When the vertices overlap with the edges, the usual fix is PerformanceGoal -> "Quality". I learned it from @halmir. $\endgroup$ – Szabolcs Jan 21 '18 at 15:55
  • $\begingroup$ @M.R. I think you should un-accept this answer in favor of Sabolcs'. His is definitely less fine-tuned. $\endgroup$ – b3m2a1 Jan 21 '18 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.