Python生成gexf文件并导入gephi做网络图分析
Gephi是一款优秀的复杂网络分析软件,支持导入多种格式的文件。gexf格式是Gephi 推荐的格式,基于 XML。本文是一个用python写的简单Demo,示例如何生成一个典型的gexf格式文件。代码基于pygexf包(下载地址:https://github.com/paulgirard/pygexf)。 代码很简单不做解释。
Python 代码:
import sys,pprint
from gexf import Gexf # test helloworld.gexf
gexf = Gexf("Gephi.org","A Web network")
graph=gexf.addGraph("directed","static","A Web network") atr1 = graph.addNodeAttribute('url',type='string')
atr2 = graph.addNodeAttribute('indegree',type='float')
atr3 = graph.addNodeAttribute('frog',type='boolean',defaultValue='true') tmp = graph.addNode("","Gephi")
tmp.addAttribute(atr1,"http://gephi.org")
tmp.addAttribute(atr2,'') tmp = graph.addNode("","Webatlas")
tmp.addAttribute(atr1,"http://webatlas.fr")
tmp.addAttribute(atr2,'') tmp = graph.addNode("","RTGI")
tmp.addAttribute(atr1,"http://rtgi.fr")
tmp.addAttribute(atr2,'') tmp = graph.addNode("","BarabasiLab")
tmp.addAttribute(atr1,"http://barabasilab.com")
tmp.addAttribute(atr2,'')
tmp.addAttribute(atr3,'false') graph.addEdge("","","",weight='')
graph.addEdge("","","",weight='')
graph.addEdge("","","",weight='')
graph.addEdge("","","",weight='')
graph.addEdge("","","",weight='') output_file=open(".\data.gexf","w")
gexf.write(output_file)
生成的最终文件data.gexf:
<?xml version='1.0' encoding='utf-8'?>
<gexf xmlns:viz="http://www.gexf.net/1.2draft/viz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.gephi.org/gexf/1.2draft" xmlns:ns0="xsi" version="1.2" ns0:schemaLocation="http://www.gephi.org/gexf/1.1draft http://gephi.org/gexf/1.2draft.xsd">
<meta lastmodified="2015-08-24">
<creator>Gephi.org</creator>
<description>A Web network</description>
</meta>
<graph defaultedgetype="directed" label="A Web network" mode="static" timeformat="double">
<attributes class="node" mode="static">
<attribute id="0" title="url" type="string"/>
<attribute id="1" title="indegree" type="float"/>
<attribute id="2" title="frog" type="boolean">
<default>true</default>
</attribute>
</attributes>
<nodes>
<node id="0" label="Gephi">
<attvalues>
<attvalue for="0" value="http://gephi.org"/>
<attvalue for="1" value="1"/>
</attvalues>
</node>
<node id="1" label="Webatlas">
<attvalues>
<attvalue for="0" value="http://webatlas.fr"/>
<attvalue for="1" value="2"/>
</attvalues>
</node>
<node id="2" label="RTGI">
<attvalues>
<attvalue for="0" value="http://rtgi.fr"/>
<attvalue for="1" value="1"/>
</attvalues>
</node>
<node id="3" label="BarabasiLab">
<attvalues>
<attvalue for="0" value="http://barabasilab.com"/>
<attvalue for="1" value="1"/>
<attvalue for="2" value="false"/>
</attvalues>
</node>
</nodes>
<edges>
<edge id="0" source="0" target="1" weight="1"/>
<edge id="1" source="0" target="2" weight="1"/>
<edge id="2" source="1" target="0" weight="1"/>
<edge id="3" source="2" target="1" weight="1"/>
<edge id="4" source="0" target="3" weight="1"/>
</edges>
</graph>
</gexf>
导入到Gephi中:

Python生成gexf文件并导入gephi做网络图分析的更多相关文章
- Python生成pyc文件
Python生成pyc文件 pyc文件是py文件编译后生成的字节码文件(byte code).pyc文件经过python解释器最终会生成机器码运行.所以pyc文件是可以跨平台部署的,类似Java的.c ...
- windows平台 python生成 pyd文件
Python的文件类型介绍: .py python的源代码文件 .pyc Python源代码import后,编译生成的字节码 .pyo Python源代码编译优化生成的字节 ...
- VNPY加密教程(Python生成pyd文件)
安装成功之后,再修改设置.让Cython可以找到vcarsall.bat.此处有两种方案.(我采用方案1,亲测可用.方案2未测试,看似可用.) 方案1:修改Python安装目录的文件设置 window ...
- Python生成pyd文件
Python的脚本文件是开源的,量化策略的安全性没有保障.因此需要保护源码.那么要对Python代码进行混淆.加密保护. 混淆代码,我准备使用pyminifier.而加密处理,就比较麻烦. Pytho ...
- python 生成 pyc 文件
以 pyc 为扩展名的是Python的编译文件.其执行速度快于 py 文件且不能用文本编辑编辑查看.所以 pyc 文件往往代替 py 文件发布. Python 在执行时,首先会将 py 文件中的源代码 ...
- python生成xml文件
先上代码: #!/usr/bin/env python3 # _*_ coding: utf-8 _*_ from xml.dom.minidom import Document def readFi ...
- C# 生成dll文件 并导入使用
首先 在unity创建一个脚本 并编写内容,其中需要调用的方法.变量要公有化(也可以直接新建cs文件用编译器打开编译,但要先导入UnityEngine.dll). 然后,复制脚本关闭unity,在外界 ...
- 使用python生成c文件模板
目标 完成一个python脚本,实现指定名字后,自动生成.c和.h的模板.例如: /** * @file epc.c * @author 陈维 * @version V01 * @date 2017. ...
- Python 动态从文件中导入类或函数的方法
假设模块文件名是data_used_to_test.py,放在tests文件夹下 文件夹结构如下: project |-tests |-data_used_to_test.py 文件内包含一个test ...
随机推荐
- 2018.07.23 codeforces 438D. The Child and Sequence(线段树)
传送门 线段树维护区间取模,单点修改,区间求和. 这题老套路了,对一个数来说,每次取模至少让它减少一半,这样每次单点修改对时间复杂度的贡献就是一个log" role="presen ...
- 一组RS485设备操作命令
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ZNJM ...
- CentOS yum 源的配置与使用(引用)
http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html
- Spring Boot的自动配置的原理浅析
一.原理描述 Spring Boot在进行SpringApplication对象实例化时会加载META-INF/spring.factories文件,将该配置文件中的配置载入到Spring容器. 二. ...
- Cadence丢失了csdCommon.dll
http://bbs.elecfans.com/jishu_450237_1_1.html
- Spring 集成 MemCache
1)xml <bean class="com.danga.MemCached.SockIOPool" factory-method="getInstance&quo ...
- Bezier曲线
1. 学习网址 http://give.zju.edu.cn/cgcourse/new/book/8.2.htm
- CodeForces - 589J —(DFS)
Masha has recently bought a cleaner robot, it can clean a floor without anybody's assistance. Schema ...
- 微软研发流程(ALM)管理培训会议(比亚迪汽车)
主要讨论和演示整体研发流程,包括需求管理.项目计划.开发管理.生成和发布.测试管理等. Figure 1 - 客户现场培训 Figure 2 - 客户现场培训 Figure 3 - 客户现场培训
- java 实例化泛型且赋值
实例化泛型 Class <T> clazz = (Class <T>) ((ParameterizedType) new Entity().getClass().getGene ...