Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

In Mathematica 9, a graph is returned as an object with head Graph:

In[8]:= CompleteGraph[8] // Head
Out[8]= Graph

Right-clicking on a Graph object brings a menu with the option "Convert to Graphics". Selecting this option returns a new object which has head Graphics. I need to do this programmatically, but I haven't found any command that, applied to CompleteGraph[8] (to put an example), returns an object with head Graphics, with a plot of the graph.

Is there a command in Mathematica to convert a Graph to a Graphics?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

Well, just after I had posted the question, I found a stupidly simple way to do it:

In[15]:= Show[CompleteGraph[8]] // Head
Out[15]= Graphics
share|improve this answer

Contextual menu bindings are defined in the file here:

FileNameJoin[{$InstallationDirectory,
  "SystemFiles", "FrontEnd", "TextResources", "ContextMenus.tr"}]

Examining the contents of that file, you can discover that the "Convert to Graphics" contextual menu item maps to the Mathematica command GraphComputation`GraphConvertToGraphics. Thus, for example,

GraphComputation`GraphConvertToGraphics[
  Graph[{1 -> 2, 2 -> 3, 3 -> 1}]] // Head

(* Out: Graphics *)

I actually prefer your Show technique, which is more natural and more likely to remain stable between versions, but it is nice to know how to find what commands these contextual menu items map to.

share|improve this answer
    
+1 Thanks. I imagine that Show probably calls GraphConvertToGraphics internally. –  becko May 11 '13 at 16:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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