有没有办法从litstudy获得静态图输出?

问题描述 投票:0回答:1

我有代码可以根据学术论文属性的

.csv
文件创建一个网络,该文件是从 Scopus 提供的在线数据库下载的。

该代码使用

litstudy
模块。这允许您将
.csv
文件加载为 doc 对象(由
litstudy
模块定义)。然后您可以根据数据创建网络,即一起发表的作者网络、引用每个文献的论文网络其他。它还使您能够绘制该网络图。当查看该模块的代码库时,我可以看到绘图功能基于
pyvis
模块。

我使用

litstudy
模块遇到的主要问题是它生成的图形具有良好的布局,但是,这些图形会移动,从而很难分析结果。我在网上读到,如果将
interactive
litstudy.network.plot_network()
属性更改为
False
,它将生成静态图。然而,当我这样做时,节点直接绘制在彼此之上。有没有办法保留该图的布局但阻止其移动。任何帮助,将不胜感激。我附上了当
interactive
属性设置为
True
(https://i.sstatic.net/F0pDnKRV.png) 以及当属性设置为
False
(https ://i.sstatic.net/etHjeBvI.png)。

代码如下:

soc_path = (
r'C:/Documents/Post_Doc/Writing_and_Learning/Lit_Review/Web_of_Science_Seagrass_Organic_Carbon.csv'
)

hab_path = (
r'C:/Documents/Post_Doc/Writing_and_Learning/Lit_Review/Web_of_Science_Seagrass_Habitat_Mapping.csv'
)

def scopus_doc_generator(path):# , year
    
    docs = litstudy.load_scopus_csv(path.replace('.csv', '_amended.csv'))
    
    #docs_refined = docs.filter_docs(lambda d: d.publication_year >= year)

    docs_found, docs_not_found = litstudy.refine_crossref(docs) 
    
    return docs_found

soc_docs_found = scopus_doc_generator(soc_path) #, 2000

hab_map_docs_found = scopus_doc_generator(hab_path) #, 2000

total_docs_found = soc_docs_found | hab_map_docs_found

coauthor_network = litstudy.build_coauthor_network(total_docs_found)

litstudy.network.plot_network(
    coauthor_network, max_node_size = 75, interactive = False
)

我尝试了以下Python代码:

soc_path = (
r'C:/Documents/Post_Doc/Writing_and_Learning/Lit_Review/Web_of_Science_Seagrass_Organic_Carbon.csv'
)

hab_path = (
r'C:/Documents/Post_Doc/Writing_and_Learning/Lit_Review/Web_of_Science_Seagrass_Habitat_Mapping.csv'
)

def scopus_doc_generator(path):# , year
    
    docs = litstudy.load_scopus_csv(path.replace('.csv', '_amended.csv'))
    
    #docs_refined = docs.filter_docs(lambda d: d.publication_year >= year)

    docs_found, docs_not_found = litstudy.refine_crossref(docs) 
    
    return docs_found

soc_docs_found = scopus_doc_generator(soc_path) #, 2000

hab_map_docs_found = scopus_doc_generator(hab_path) #, 2000

total_docs_found = soc_docs_found | hab_map_docs_found

coauthor_network = litstudy.build_coauthor_network(total_docs_found)

litstudy.network.plot_network(
    coauthor_network, max_node_size = 75, interactive = False
)

我期望得到一个静态图输出,其中的节点彼此不重叠。

编辑:

我将两个笔记本的数据存储在以下存储库中:

soc_csv

hab_csv

解决方案:

我在 GitHub 对话中找到了该问题的解决方案,内容涉及在

pyvis
图表达到稳定后停止物理现象。当 @furas 暗示这可能是一个 Javascript 问题时,他们提到了这一点。

如果将 GitHub 概述的行添加到

template.html
站点包的模板文件夹中的
pyvis
文件中,则可以将以下两行添加到
plot_network
文件的
network.py
函数中
litstudy
包然后你就得到稳定的输出:

template_dir = 'wherever you have saved the new template.html file'
v.set_template_dir(template_dir)

return v.show(file_name)
python html networkx
1个回答
1
投票

解决方案:

我在 GitHub 对话中找到了该问题的解决方案,该对话涉及在 pyvis 图达到稳定后停止物理现象。当 @furas 暗示这可能是一个 Javascript 问题时,他们提到了这一点。 GitHub 上概述了初步修复。

如果将

template.html
pyvis
站点包的模板文件夹复制到计算机中的其他位置,则可以添加以下行:

network.once("stabilizationIterationsDone", function() { document.getElementById('text').innerHTML = '100%'; document.getElementById('bar').style.width = '496px'; document.getElementById('loadingBar').style.opacity = 0; // really clean the dom element
setTimeout(function () {document.getElementById('loadingBar').style.display = 'none';}, 500); // add this line network.setOptions( { physics: false } ); }); // start block addition {% else %} network.on("stabilizationIterationsDone", function() { network.setOptions(
{ physics: false } ); }); //end block addition {% endif %}

然后您可以将以下两行添加到litstudy包的

plot_network
文件的
network.py
函数中,然后您将获得稳定的输出:

template_dir = 'C:/Users/gerar/Documents/Templates/template.html'
v.set_template_dir(template_dir)

return v.show(file_name)
© www.soinside.com 2019 - 2024. All rights reserved.