最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python利用networkx畫圖繪制Les?Misérables人物關(guān)系

 更新時間:2022年05月11日 16:01:30   作者:Cyril_KI  
這篇文章主要為大家介紹了Python利用networkx畫圖處理繪制Les?Misérables悲慘世界里的人物關(guān)系圖,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

數(shù)據(jù)集介紹

《悲慘世界》中的人物關(guān)系圖,圖中共77個節(jié)點、254條邊。

數(shù)據(jù)集截圖:

打開README文件:

Les Misérables network, part of the Koblenz Network Collection
===========================================================================
This directory contains the TSV and related files of the moreno_lesmis network: This undirected network contains co-occurances of characters in Victor Hugo's novel 'Les Misérables'. A node represents a character and an edge between two nodes shows that these two characters appeared in the same chapter of the the book. The weight of each link indicates how often such a co-appearance occured.
More information about the network is provided here: 
http://konect.cc/networks/moreno_lesmis
Files: 
    meta.moreno_lesmis -- Metadata about the network 
    out.moreno_lesmis -- The adjacency matrix of the network in whitespace-separated values format, with one edge per line
      The meaning of the columns in out.moreno_lesmis are: 
        First column: ID of from node 
        Second column: ID of to node
        Third column (if present): weight or multiplicity of edge
        Fourth column (if present):  timestamp of edges Unix time
        Third column: edge weight
Use the following References for citation:
@MISC{konect:2017:moreno_lesmis,
    title = {Les Misérables network dataset -- {KONECT}},
    month = oct,
    year = {2017},
    url = {http://konect.cc/networks/moreno_lesmis}
}
@book{konect:knuth1993,
	title = {The {Stanford} {GraphBase}: A Platform for Combinatorial Computing},
	author = {Knuth, Donald Ervin},
	volume = {37},
	year = {1993},
	publisher = {Addison-Wesley Reading},
}
@book{konect:knuth1993,
	title = {The {Stanford} {GraphBase}: A Platform for Combinatorial Computing},
	author = {Knuth, Donald Ervin},
	volume = {37},
	year = {1993},
	publisher = {Addison-Wesley Reading},
}
@inproceedings{konect,
	title = {{KONECT} -- {The} {Koblenz} {Network} {Collection}},
	author = {Jér?me Kunegis},
	year = {2013},
	booktitle = {Proc. Int. Conf. on World Wide Web Companion},
	pages = {1343--1350},
	url = {http://dl.acm.org/citation.cfm?id=2488173},
	url_presentation = {https://www.slideshare.net/kunegis/presentationwow},
	url_web = {http://konect.cc/},
	url_citations = {https://scholar.google.com/scholar?cites=7174338004474749050},
}
@inproceedings{konect,
	title = {{KONECT} -- {The} {Koblenz} {Network} {Collection}},
	author = {Jér?me Kunegis},
	year = {2013},
	booktitle = {Proc. Int. Conf. on World Wide Web Companion},
	pages = {1343--1350},
	url = {http://dl.acm.org/citation.cfm?id=2488173},
	url_presentation = {https://www.slideshare.net/kunegis/presentationwow},
	url_web = {http://konect.cc/},
	url_citations = {https://scholar.google.com/scholar?cites=7174338004474749050},
}

從中可以得知:該圖是一個無向圖,節(jié)點表示《悲慘世界》中的人物,兩個節(jié)點之間的邊表示這兩個人物出現(xiàn)在書的同一章,邊的權(quán)重表示兩個人物(節(jié)點)出現(xiàn)在同一章中的頻率。

真正的數(shù)據(jù)在out.moreno_lesmis_lesmis中,打開并另存為csv文件:

數(shù)據(jù)處理

networkx中對無向圖的初始化代碼為:

g = nx.Graph()
g.add_nodes_from([i for i in range(1, 78)])
g.add_edges_from([(1, 2, {'weight': 1})])

節(jié)點的初始化很容易解決,我們主要解決邊的初始化:先將dataframe轉(zhuǎn)為列表,然后將其中每個元素轉(zhuǎn)為元組。

df = pd.read_csv('out.csv')
res = df.values.tolist()
for i in range(len(res)):
    res[i][2] = dict({'weight': res[i][2]})
res = [tuple(x) for x in res]
print(res)

res輸出如下(部分):

[(1, 2, {'weight': 1}), (2, 3, {'weight': 8}), (2, 4, {'weight': 10}), (2, 5, {'weight': 1}), (2, 6, {'weight': 1}), (2, 7, {'weight': 1}), (2, 8, {'weight': 1})...]

因此圖的初始化代碼為:

g = nx.Graph()
g.add_nodes_from([i for i in range(1, 78)])
g.add_edges_from(res)

畫圖

nx.draw(g)
plt.show()

networkx自帶的數(shù)據(jù)集

忙活了半天發(fā)現(xiàn)networkx有自帶的數(shù)據(jù)集,其中就有悲慘世界的人物關(guān)系圖:

g = nx.les_miserables_graph()
nx.draw(g, with_labels=True)
plt.show()

完整代碼

# -*- coding: utf-8 -*-
import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
# 77 254
df = pd.read_csv('out.csv')
res = df.values.tolist()
for i in range(len(res)):
    res[i][2] = dict({'weight': res[i][2]})
res = [tuple(x) for x in res]
print(res)
# 初始化圖
g = nx.Graph()
g.add_nodes_from([i for i in range(1, 78)])
g.add_edges_from(res)
g = nx.les_miserables_graph()
nx.draw(g, with_labels=True)
plt.show()

以上就是Python利用networkx畫圖繪制Les Misérables人物關(guān)系的詳細內(nèi)容,更多關(guān)于Python networkx畫圖繪制的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python使用Altair創(chuàng)建交互式數(shù)據(jù)可視化的操作指南

    Python使用Altair創(chuàng)建交互式數(shù)據(jù)可視化的操作指南

    Altair 是一個基于 Vega-Lite 的 Python 數(shù)據(jù)可視化庫,它旨在簡化數(shù)據(jù)可視化的創(chuàng)建過程,尤其適用于統(tǒng)計圖表的生成,Altair 強調(diào)聲明式編碼方式,通過簡單的語法,用戶能夠快速創(chuàng)建復(fù)雜的交互式圖表,本文將介紹 Altair 的基礎(chǔ)用法、常見圖表類型,需要的朋友可以參考下
    2024-12-12
  • Python簡單讀寫Xls格式文檔的方法示例

    Python簡單讀寫Xls格式文檔的方法示例

    這篇文章主要介紹了Python簡單讀寫Xls格式文檔的方法,結(jié)合實例形式分析了Python中xlrd和xlwt模塊的安裝及針對xls格式文檔的相關(guān)讀寫操作實現(xiàn)技巧,需要的朋友可以參考下
    2018-08-08
  • 在python3.9下如何安裝scrapy的方法

    在python3.9下如何安裝scrapy的方法

    這篇文章主要介紹了在python3.9下如何安裝scrapy的方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-02-02
  • Python模塊學(xué)習(xí) filecmp 文件比較

    Python模塊學(xué)習(xí) filecmp 文件比較

    filecmp模塊用于比較文件及文件夾的內(nèi)容,它是一個輕量級的工具,使用非常簡單。python標準庫還提供了difflib模塊用于比較文件的內(nèi)容。關(guān)于difflib模塊,且聽下回分解
    2012-08-08
  • python format 格式化輸出方法

    python format 格式化輸出方法

    今天小編就為大家分享一篇python format 格式化輸出方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • python 截取XML中bndbox的坐標中的圖像,另存為jpg的實例

    python 截取XML中bndbox的坐標中的圖像,另存為jpg的實例

    這篇文章主要介紹了python 截取XML中bndbox的坐標中的圖像,另存為jpg的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • python人工智能深度學(xué)習(xí)算法優(yōu)化

    python人工智能深度學(xué)習(xí)算法優(yōu)化

    這篇文章主要為大家介紹了python人工智能深度學(xué)習(xí)關(guān)于算法優(yōu)化詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2021-11-11
  • Pytorch使用Visdom進行數(shù)據(jù)可視化的示例代碼

    Pytorch使用Visdom進行數(shù)據(jù)可視化的示例代碼

    pytorch Visdom可視化,是一個靈活的工具,用于創(chuàng)建,組織和共享實時豐富數(shù)據(jù)的可視化,這個博客簡要介紹一下在使用Pytorch進行數(shù)據(jù)可視化的一些內(nèi)容,感興趣的朋友可以參考下
    2023-12-12
  • 用Python刪除本地目錄下某一時間點之前創(chuàng)建的所有文件的實例

    用Python刪除本地目錄下某一時間點之前創(chuàng)建的所有文件的實例

    下面小編就為大家分享一篇用Python刪除本地目錄下某一時間點之前創(chuàng)建的所有文件的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2017-12-12
  • python集合刪除多種方法詳解

    python集合刪除多種方法詳解

    這篇文章主要介紹了python集合刪除多種方法詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-02-02

最新評論

老河口市| 龙江县| 巫溪县| 天门市| 朝阳县| 青田县| 雷州市| 宝清县| 石首市| 林口县| 芷江| 南江县| 吐鲁番市| 乐平市| 南昌县| 建昌县| 泰顺县| 六盘水市| 孝义市| 鄂托克前旗| 绩溪县| 屏南县| 体育| 房产| 清河县| 宝坻区| 沙坪坝区| 富顺县| 含山县| 枞阳县| 北碚区| 萨嘎县| 日照市| 裕民县| 隆德县| 绵阳市| 高邮市| 荣成市| 丹江口市| 太白县| 依兰县|