我正在搜索一个绘制时空图的例子。我浏览了Graphviz,但找不到相关的示例。我必须绘制一张计算机网络图,假设网络在10秒后发生变化。我可以绘制一个场景,但现在我需要将在不同时间获得的不同图组合为时空图。我正在使用python进行绘图,但任何相关的示例与任何工具,如Graphviz,matplotlib,networkx等将是有帮助的。
因此,任何关于这方面的建议和指导方针都将受到高度赞赏。
谢谢
发布于 2012-09-16 20:28:34
谢谢你的回复。我已经在做一些事情了,所以如果我不能做到这一点,我会按照你的建议去做。到目前为止,我有:

但我想要这样的东西:

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“。
发布于 2012-09-16 01:27:57
我会使用matplotilb来做这件事。这是最小的代码。使用散点可能会更有效,而不是单独绘制点,并使用NaN对不连续的线进行游戏,但这将会起作用。有关椭圆示例,请参见here。text documentation,或者如果你想更花哨,注释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)https://stackoverflow.com/questions/12429778
复制相似问题