python?gravis庫實(shí)現(xiàn)圖形數(shù)據(jù)可視化實(shí)例探索
python gravis庫
今天給大家分享一個(gè)神奇的 python 庫,gravis
gravis(Graph Visualization Software)是一個(gè)用于圖形數(shù)據(jù)可視化的 Python 庫。它專注于提供一個(gè)簡(jiǎn)單、高效、可定制的方式來展示和探索圖形數(shù)據(jù)。
它使用 Python 來準(zhǔn)備圖形數(shù)據(jù)并使用 Web 技術(shù) (HTML/CSS/JS) 來呈現(xiàn)圖形數(shù)據(jù),主要基于 JavaScript 庫 d3.js、 vis.js 和 3d-force-graph.js/ Three.js。結(jié)果可以顯示在 Web 瀏覽器窗口中、嵌入 Jupyter Notebook 中、導(dǎo)出到獨(dú)立的 HTML 文件或在 Web 應(yīng)用程序中作為 HTML 文本使用。還支持以 JPG、PNG 和 SVG 格式導(dǎo)出靜態(tài)圖像。
gravis 庫的一些主要特點(diǎn)
易用性,它提供了一個(gè)簡(jiǎn)潔的API來創(chuàng)建和操作圖形可視化。
與其他圖形庫兼容,gravis 可以與其他流行的圖形處理庫(如 NetworkX、igraph 等)結(jié)合使用。這意味著你可以用這些庫來創(chuàng)建和處理圖形,然后使用 gravis 來進(jìn)行可視化。
交互性,gravis 生成的圖形可視化通常是交互式的,這使用戶可以通過縮放、平移、懸停等操作來更好地探索圖形。
可定制性,提供了許多定制選項(xiàng),比如節(jié)點(diǎn)和邊的樣式、布局算法的選擇等,使用戶可以根據(jù)需求調(diào)整可視化的外觀和行為。
多種輸出格式,gravis 支持多種輸出格式,包括在 Jupyter Notebook 中直接顯示,或者導(dǎo)出為 HTML 文件、圖片等。
庫的安裝
可以直接通過 pip 進(jìn)行安裝。
pip install gravis
圖形生成器
這里,我們使用 nx.dual_barabasi_albert_graph 來生成包含 30 個(gè)節(jié)點(diǎn)的隨機(jī)圖,然后分別對(duì)結(jié)點(diǎn)和邊添加一些屬性。
import uuid import networkx as nx def get_new_test_graph(): NUM_NODES = 30 p = 0.5 seed = 1 test_graph = nx.dual_barabasi_albert_graph(n=NUM_NODES, p=p, seed=seed, m1=2, m2=1) # add node properties nx.set_node_attributes(test_graph, dict(test_graph.degree()), name='degree') nx.set_node_attributes(test_graph, nx.betweenness_centrality(test_graph), name='betweenness_centrality') for node, data in test_graph.nodes(data=True): data['node_identifier'] = str(uuid.uuid4()) data['feature1'] = np.random.random() data['feature2'] = np.random.randint(0, high=100) data['feature3'] = 1 if np.random.random() > 0.5 else 0 # add edge properties for _, _, data in test_graph.edges(data=True): data['feature1'] = np.random.random() data['feature2'] = np.random.randint(0, high=100) return test_graph
當(dāng)我們使用 networkx 繪制圖表時(shí),我們得到以下結(jié)果。
test_graph = get_new_test_graph() nx.draw(test_graph)
使用 gravis 畫圖
import gravis as gv gv.d3( test_graph, # graph specs graph_height=500, # node specs node_size_data_source="betweenness_centrality", use_node_size_normalization=True, node_size_normalization_min=15, node_size_normalization_max=35, show_node_label=True, node_label_data_source='node_identifier', # edge specs edge_size_data_source='feature1', use_edge_size_normalization=True, edge_size_normalization_min=1, edge_size_normalization_max=5, # force-directed graph specs many_body_force_strength=-500 )
以上就是python gravis庫實(shí)現(xiàn)圖形數(shù)據(jù)可視化實(shí)例探索的詳細(xì)內(nèi)容,更多關(guān)于python gravis庫的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- python?AutoViz庫一行代碼實(shí)現(xiàn)可視化數(shù)據(jù)集
- python可視化數(shù)據(jù)分析pyecharts初步嘗試
- Python?VisPy庫高性能科學(xué)可視化圖形處理用法實(shí)例探究
- Python pydotplus安裝及可視化圖形創(chuàng)建教程
- python Dtale庫交互式數(shù)據(jù)探索分析和可視化界面
- python?Sweetviz探索性數(shù)據(jù)可視化分析庫使用特征詳解
- Python mplfinance庫繪制金融圖表實(shí)現(xiàn)數(shù)據(jù)可視化實(shí)例探究
- python?pyvis庫創(chuàng)建可視化交互式網(wǎng)絡(luò)圖
相關(guān)文章
python manage.py runserver流程解析
這篇文章主要介紹了python manage.py runserver流程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11分析解決Python中sqlalchemy數(shù)據(jù)庫連接池QueuePool異常
這篇文章主要來給大家分析sqlalchemy數(shù)據(jù)庫連接池QueuePool的異常,給大家用詳細(xì)的圖文方式做出了解決的方案,有需要的朋友可以借鑒參考下,希望可以有所幫助2021-09-09Python利用filestools模塊實(shí)現(xiàn)水印添加
最近發(fā)現(xiàn)的這款filestools非標(biāo)準(zhǔn)庫其實(shí)真正實(shí)現(xiàn)添加水印的只要一個(gè)函數(shù)的調(diào)用,一行代碼即可完成水印的添加,感興趣的快跟隨小編一起學(xué)起來吧2022-09-09聊聊python里如何用Borg pattern實(shí)現(xiàn)的單例模式
這篇文章主要介紹了聊聊python里如何用Borg pattern實(shí)現(xiàn)的單例模式,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-06-06分享一個(gè)可以生成各種進(jìn)制格式IP的小工具實(shí)例代碼
這篇文章主要給大家分享了一個(gè)可以生成各種進(jìn)制格式IP的小工具,利用的語言是python實(shí)現(xiàn)的一個(gè)小工具,這個(gè)小工具對(duì)大家的日常使用與開發(fā)具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起看看吧。2017-07-07Python中index()函數(shù)與find()函數(shù)的區(qū)別詳解
這篇文章主要介紹了Python中index()函數(shù)與find()函數(shù)的區(qū)別詳解,Python index()方法檢測(cè)字符串中是否包含子字符串 str ,如果指定beg開始和end結(jié)束范圍,則檢查是否包含在指定范圍內(nèi),需要的朋友可以參考下2023-08-08python抓取某汽車網(wǎng)數(shù)據(jù)解析html存入excel示例
python抓取某汽車網(wǎng)經(jīng)銷商信息網(wǎng)頁數(shù)據(jù)解析html,這里提供一個(gè)示例演示,大家可以根據(jù)需要分析自己網(wǎng)站的數(shù)據(jù)2013-12-12