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

In[1]:= CompleteGraph[8] // Head
Out[1]= 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?


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

In[1]:= Show[CompleteGraph[8]] // Head
Out[1]= Graphics

Contextual menu bindings are defined in the file here:

  "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,

  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.

  • $\begingroup$ +1 Thanks. I imagine that Show probably calls GraphConvertToGraphics internally. $\endgroup$ – becko May 11 '13 at 16:54

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.