pygraphviz经典例子

#1

import pygraphviz as pgv
# 创建图形
G = pgv.AGraph(directed=True, strict=False, nodesep=0.1, ranksep=0.5,
               splines="spline", concentrate=False, bgcolor="white",
               compound=False, normalize=False, encoding='UTF-8')#True

# 添加节点
li_nodes = ["0图像", 1, 2, 3, 4]
for i in li_nodes:
    G.add_node(i, style="filled", shape="box", color="#B4E7B7", fontname="SimSun",
               fontsize=11, fontcolor="black")#polygon

# 添加边
li_edges_nodes = [["0图像", 1], ["0图像", 2],["0图像",3],["0图像",4],[4,"0图像"],[4,1],[4,2],[4,3],[1,2],
                 [2,3],[3,1],[2,1]]
li_edges_labels = ["666", 2, "", 5, "fjj", "label", "hdj", "hello/nworld |{ b |{c|<here> d|e}| f}| g | h", 86, "ul", "ppp","999"]
li_a0 = ["H","N","H","N","N","H","N","H","N","N","N","N"]
li_a1 = ["N","H","N","N","N","H","N","H","N","N","N","N"]
li_a2 = ["H","N","B","N","H","H","N","H","N","N","N","N"]
n_edges = len(li_edges_nodes)
for i in range(n_edges):
    G.add_edge(li_edges_nodes[i][0], li_edges_nodes[i][1],label = li_edges_labels[i],
               a0 = li_a0[i], a1 = li_a1[i], a2 = li_a2[i],color="#7F01FF", arrowsize=0.6)

# 图输出
G.layout()
print(G.string())
path_temp = "G_temp.png"
G.draw(path_temp, format='png', prog='dot')

im = Image.open(path_temp)
#display(im)
im.show()


# cb = G.get_edge("0图像", 4)
# label000 = cb.attr['label']
# a000 = cb.attr['a0']
# print('label:', label000)
# print('a0:', a000)

#2

#因子相关性图
G = pgv.AGraph(directed=True, rankdir="TB")

# 设置节点标签
Root = u"道路交通流畅"
negative_1 = u"平均延误时间"
negative_2 = u"负荷度"
negative_3 = u"小区位置"
negative_4 = u"相对延误率"
negative_5 = u"房屋密度"
negative_6 = u"人口密度"
negative_7 = u"总延误率"
negative_8 = u"排队率"
negative_9 = u"行驶时间"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值