用绘图绘制图形的库。
igviz的Python项目详细描述
交互式图形可视化
目录
简介
交互式图形可视化(igviz)是一个帮助以绘图方式交互式地可视化图形的库。这个库提供了一个可定制的api,用于在一个整洁、视觉上吸引人的绘图中可视化图形。它通过显示最少的文本信息来保持更大的图形更干净,并使用颜色和大小突出显示节点属性和关系,同时在需要时提供相同的文本信息。在
使用
示例笔记本可以找到here。在
基本
importnetworkxasnximportigvizasigG=nx.random_geometric_graph(200,0.125)nx.set_node_attributes(G,3,"prop")nx.set_edge_attributes(G,5,"edge_prop")ig.plot(G)
默认的打印颜色和大小节点的程度,但它是可配置的。在
配置
^{pr2}$ig.plot(G,title="My Graph",size_method="prop",# Makes node sizes the size of the "prop" propertycolor_method="prop",# Colors the nodes based off the "prop" property and a color scale,node_text=["prop"],# Adds the 'prop' property to the hover text of the node)
ig.plot(G,node_label="prop",# Display the "prop" attribute as a label on the nodenode_label_position="top center",# Display the node label directly above the nodeedge_text=["edge_prop"],# Display the "edge_prop" attribute on hover over the edgeedge_label="edge_prop",# Display the "edge_prop" attribute on the edgeedge_label_position="bottom center",# Display the edge label below the edge)
如何添加自定义的大小调整方法和颜色方法
要添加您自己的自定义大小和颜色方法,只需将一个列表传递给size_method
和color_method
。在
color_list=[]sizing_list=[]fornodeinG.nodes():size_and_color=G.degree(node)*3color_list.append(size_and_color)sizing_list.append(size_and_color)ig.plot(G,title="My Graph",size_method=sizing_list,# Makes node sizes the size of the "prop" propertycolor_method=color_list,# Colors the nodes based off the "prop" property and a color scale,node_text=["prop"],# Adds the 'prop' property to the hover text of the node)
应用布局
所有布局都是通过每个节点上的pos
属性计算的。Networkx内置了布局,您可以使用,也可以通过igviz调用。在
ig.plot(G,title="My Graph",layout="kamada",)
要添加您自己的pos
属性,可以通过nx.set_node_attributes
函数进行设置。在
pos_dict={0:[1,2],# X, Y coordinates for Node 01:[1.5,3],# X, Y coordinates for Node 1...}nx.set_node_attributes(G,pos_dict,"pos")ig.plot(G)
有向图和多图
Igviz还绘制有向图和多重图,没有配置变化。对于有向图,箭头在节点之间显示。对于多图,只显示一条边,建议通过edge_label
或edge_text
来显示两个多图节点之间所有边的权重。在
有向图
defcreateDiGraph():# Create a directed graph (digraph) object; i.e., a graph in which the edges# have a direction associated with them.G=nx.DiGraph()# Add nodes:nodes=['A','B','C','D','E']G.add_nodes_from(nodes)# Add edges or links between the nodes:edges=[('A','B'),('B','C'),('B','D'),('D','E')]G.add_edges_from(edges)returnGDG=createDiGraph()ig.plot(DG,size_method="static")
多图
MG=nx.MultiGraph()MG.add_weighted_edges_from([(1,2,0.5),(1,2,0.75),(2,3,0.5)])ig.plot(MG,layout="spring",size_method="static",edge_text=["weight"],colorscale="Rainbow")
安装
pip install igviz
可自定义参数
- 在
title:图形的标题,默认为“graph”
在 - 在
布局:图上节点的布局(“随机”、“圆形”、“kamada”、“平面”、“弹簧”、“光谱”、“螺旋”},可选)。在
在 - 在
size_方法:如何调整节点大小,默认为“degree”
在 - 在
color_方法:如何给节点上色,默认为“degree”
在 - 在
node_label:要在节点上显示的节点属性。在
在 - 在
节点标签位置:节点标签的位置。在
在 - 在
node_text:悬停在节点上时要显示的节点属性列表。在
在 - 在
edge_label:要在边缘上显示的edge属性。在
在 - 在
边缘标签位置:边缘标签的位置。在
在 - 在
边缘文本:悬停在边缘上时要显示的边缘属性列表。在
在 - 在
titlefont_size:标题的字体大小,默认为16
在 - 在
annotation_text:图形注释文本
在 - 在
colorscale:颜色条的刻度('Greys'、'YlGnBu'、'Greens'、'YlOrRd'、'Bluered'、'RdBu'、'Blues'、'Blues'、'Blues'、'bluit'、'borland'、'Jet'、'Hot'、'Blackbody'、'Earth'、'Electric'、'virid
在 - 在
colorbar_title:颜色条轴标题。在
在 - 在
节点不透明度:节点的不透明度(1-填充,0完全透明),默认为1
在 - 在
arrow_size:有向图和多重图的箭头大小,默认为2。在
在
反馈
我很感谢任何反馈,因此如果您有任何功能请求或问题,请使用适当的标签或更进一步,请发送电子邮件至ashton.sidhu1994@gmail.com
贡献者
这个项目遵循all-contributors规范,由这些awesome contributors提供给您。在
- 项目
标签: