我有一个数据框central
![enter image description here](https://i.stack.imgur.com/FgaPM.png)
然后我想绘制列之间的成对关系sns.pairplot(central)
。您能解释一下为什么这个过程会永远运行吗?我在我的笔记本电脑和 Colab 上都尝试过,但问题仍然存在。
import urllib3
%matplotlib inline
%config InlineBackend.figure_format = 'svg' # Change the image format to svg for better quality
import networkx as nx
import pandas as pd
import seaborn as sns
from scipy import stats
import matplotlib.pyplot as plt
## Import dataset
http = urllib3.PoolManager()
url = 'https://raw.githubusercontent.com/leanhdung1994/WebMining/main/airports.net'
f = http.request('GET', url)
open('airports.net', 'wb').write(f.data)
G = nx.read_pajek('airports.net', encoding = 'UTF-8')
G = nx.DiGraph(G)
## Compute measures of centrality
degree_central = nx.degree_centrality(G)
closeness_central = nx.closeness_centrality(G)
eigen_central = nx.eigenvector_centrality_numpy(G, max_iter = 200)
katz_central = nx.katz_centrality_numpy(G)
between_central = nx.betweenness_centrality(G)
pagerank = nx.pagerank_numpy(G)
[hub, authority] = nx.hits(G)
## Create a dataframe using with above calculated centralities
central = pd.DataFrame([degree_central, closeness_central, eigen_central, katz_central, between_central, hub, authority]).T
central.columns = ['degree', 'closeness', 'eigen', 'katz', 'between', 'hub', 'authority']
central
## Plot the pairwise relationships between centralities
sns.pairplot(central)
由于我未知的原因,列的直方图eigen_central
在确定合理的垃圾箱数量时存在问题。配对图与对角线中的 kde 图配合使用sns.pairplot(central, diag_kind="kde")
,以及列的直方图eigen_central
单独使用也无法按预期工作。您可以通过定义 bin 编号来解决此问题:
sns.pairplot(central, diag_kws = {"bins": 10})
Output:
![enter image description here](https://i.stack.imgur.com/wormp.png)
我将投票支持任何能够提供seaborn 在定义垃圾箱时遇到问题的原因的答案。这个问题是seaborn特有的plt.hist(central.eigen)
按预期工作,但没有sns.histplot(central.eigen)
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)