2012-09-14 75 views
0

我正在搜索绘制空间时间图的示例。我经历了Graphviz,但找不到相关示例。我必须绘制计算机网络的图形,并假定网络在10秒后发生变化。我可以绘制一个场景,但现在我需要将不同时间获得的不同图形组合为一个空间时间图。 我使用python进行绘图但是任何有关Graphviz,matplotlib,networkx等工具的相关示例都会有所帮助。在python中绘制空间时间图

因此,任何有关这方面的建议和指导是高度赞赏。

谢谢

+0

你能提供一个空间时间图表的例子吗?我对这些短语的解释涉及相对论,我怀疑这不是你想要的(http://en.wikipedia.org/wiki/Minkowski_diagram)。 – tacaswell

+0

我想要像这样的图像http://imageshack.us/a/img521/9890/spacetimegraph.png。 在时间= 0时,节点B,C和D连接,并且A是单独的。 在时间= 10时,连接节点A和B. C和D也连接在一起。 依此类推.... – OSMuser

+0

你应该接受你自己对这个问题的回答。 – tacaswell

回答

0

谢谢tcaswell的回复。我已经在做一些事情,所以如果我不能这样做,我会深入到你所建议的方式。现在我有: enter image description here

但我想是这样的:

enter image description here

使用GraphViz的创建这个图片.DOT文件代码:

graph { 
    rankdir=LR; 
    subgraph cluster01 { 
     label="t=0" 
     a0 [label="A"]; 
     a1 [label="B"]; 
     a2 [label="C"]; 
     a5 [label="E"]; 
     a0 -- a1; 
     a1 -- a2 ; 
     a2 -- a0; 
    }; 

    subgraph cluster02 
    { 
     label="t=10" 
     b0 [label="A"]; 
     b5 [label="E"]; 
     b1 [label="B"]; 
     b2 [label="C"]; 

     b0 -- b1; 
     b2 -- b5; 
    }; 

    a0--b0 [style=dotted]; 
    a1--b1 [style=dotted]; 
    a2--b2 [style=dotted]; 
    a5--b5 [style=dotted]; 
} 

我想我我无法正确玩弄“rankdir”。

+0

这个问题就解决了: http://stackoverflow.com/questions/12463541/subgraph-layout-in-graphviz – OSMuser

0

我会用matplotilb做到这一点。这是最小的代码。使用散点图而不是单独绘制点和使用不连续线的NaN游戏可能会更有效率,但这种方法可行。有关椭圆示例,请参见heretextdocumentation,或者如果你想成为fancier注释doc

import matplotlib.pyplot as plt 
import numpy as np 

def plot_level(ax,t,location_map, link_pairs,shift_scale = 10): 
    # add some code that adds the ellipse + time label  
    shift = np.array([0,t*shift_scale]) 

    # plot nodes + labels 
    for key in location_map: 
     pt_location = location_map[key] + shift 
     ax.plot(pt_location[0],pt_location[1],'ok') 
     ax.text(pt_location[0],pt_location[1],key + "%d"%t) # play with this to make it look good 

    # plot connections 
    for a,b in link_pairs: 
     ax.plot(*(np.vstack((location_map[a],location_map[b])) + shift.T).T,color='k') 
    plt.draw() 


location_map = {} 
location_map['A'] = np.array([0,0]) 
location_map['B'] = np.array([1,1]) 
location_map['C'] = np.array([2,0]) 
location_map['D'] = np.array([3,1]) 

link_pairs1 = [('A','B')] 
link_pairs2 = [('B','C')] 

fig = plt.figure() 
ax = plt.gca() 
ax.yaxis.set_visible(False) 
ax.xaxis.set_visible(False) 
# function_that_draws_axes_marker 
plot_level(gca(),0,location_map,[]) 
plot_level(gca(),1,location_map,link_pairs1) 
plot_level(gca(),2,location_map,link_pairs2) 
# function_that_draws_vertical_lines(t_range,location_map,shift_scale=10)