如何解决为什么 seaborn.pairplot 无法完成绘制此图?
我有一个数据框 central
然后我想用 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
的 histplot 在确定合理的 bin 数量时出现问题。 pairplot 与对角线 sns.pairplot(central,diag_kind="kde")
中的 kde 图一起使用,单独列 eigen_central
的 histplot 也无法按预期工作。您可以通过定义 bin 编号来解决这个问题:
sns.pairplot(central,diag_kws = {"bins": 10})
我会赞成任何可以解释为什么 seaborn 在定义垃圾箱时遇到问题的答案。此问题是特定于 seaborn 的,因为 plt.hist(central.eigen)
按预期工作,但不是 sns.histplot(central.eigen)
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。