问题描述
我想从Gephi图中提取Giant组件。我目前正在处理一个太大而无法使用Gephi自己的巨型组件函数的图形,Gephi会冻结。因此,我现在的问题是,我只想从我的edges.csv文件中提取出巨人组件中的节点,以便能够删除巨人组件中未包括的所有节点,从而使文件更小且可用于Gephi。 / p>
我想使用Python解决此问题,并且我知道python有一个名为networkx的库,我的问题可以通过networkx轻松解决吗? 我的edges.csv的格式为:
source,target,weight
nodeA,nodeB,1
nodeA,nodeC,nodeD,1
nodeB,nodeA,1
nodeD,1
解决方法
您可以从pandas DataFrame中读取图形,并使用JDesktopPane desktop = new JDesktopPane()
{
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
String text = "drag and drop here";
FontMetrics fm = g.getFontMetrics();
int stringWidth = fm.stringWidth( text );
int x = (getWidth() - stringWidth) / 2;
int y = getHeight() / 2;
g.drawString(text,x,y);
};
}
函数A Closer Look at the Paint Mechanism将图形拆分为连接的组件,然后从中获取最大的组件。
读取图并制作networkx图的示例
connected_component_subgraphs
获取连接的组件和最大的组件的示例
edge_list_df = pd.read_csv('edges.csv')
g = nx.pandas_edgelist(edge_list_df,source='source',target='target',edge_attr='weight')