防止在Mathematica 8中自动布局Graph []对象

Sza*_*lcs 6 wolfram-mathematica mathematica-8

某些类型的对象在Mathematica中具有特殊的输入/输出格式.这包括Graphics光栅图像,以及Mathematica 8的图形(Graph[]).遗憾的是,大型图形可能需要很长时间才能实现可视化,这比我在交互式工作期间对其进行的大多数其他操作要长得多.

如何防止Graph[]StandardForm和TraditionalForm 中对象的自动布局,并将它们显示为例如-Graph-,最好保留输出的可解释性(可能使用Interpretation?).我认为这将涉及改变Format和/或MakeBoxes以某种方式,但我没有成功实现这一点.

我想以可逆的方式执行此操作,并且最好定义一个函数,该函数在应用于Graph对象(不同于GraphPlot非交互式对象)时将返回原始交互式图形显示.

在相关的说明中,有没有办法检索与某些符号关联的Format/MakeBoxes定义? FormatValues是一个相关的功能,但它是空的Graph.

示例会话:

In[1]:= Graph[{1->2, 2->3, 3->1}]
Out[1]= -Graph-

In[2]:= interactiveGraphPlot[%] (* note that % works *)
Out[2]= (the usual interactive graph plot should be shown here)
Run Code Online (Sandbox Code Playgroud)

Mr.*_*ard 2

虽然我没有 Mathematica 8 来尝试这个,但一种可能性是使用这个构造:

Unprotect[Graph]

MakeBoxes[g_Graph, StandardForm] /; TrueQ[$short] ^:= 
 ToBoxes@Interpretation[Skeleton["Graph"], g]

$short = True;
Run Code Online (Sandbox Code Playgroud)

之后,Graph对象应以骨架形式显示,并且设置$short = False应恢复默认行为。

希望这可以实现自动切换:

interactiveGraphPlot[g_Graph] := Block[{$short}, Print[g]]
Run Code Online (Sandbox Code Playgroud)

马克对修改的担忧Graph使我考虑使用$PrePrint. 我认为这也应该可以防止发生缓慢的布局步骤。假设您还没有用于$PrePrint其他用途,这可能会更理想。

$PrePrint = 
  If[TrueQ[$short], # /. _Graph -> Skeleton["Graph"], #] &;

$short = True
Run Code Online (Sandbox Code Playgroud)

也很方便,至少使用Graphics(我再次无法在 v7 中测试Graph)你可以简单地获得图形Print。这里用图形显示:

g = Plot[Sin[x], {x, 0, 2 Pi}]

(*  Out =  <<"Graphics">>  *)
Run Code Online (Sandbox Code Playgroud)

然后

Print[g]
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我将$short测试留在原处,以便通过全局符号轻松切换,但也可以将其省略并使用:

    $PrePrint = # /. _Graph -> Skeleton["Graph"] &;
Run Code Online (Sandbox Code Playgroud)

然后使用$PrePrint = .重置默认功能。