为什么 seaborn.pairplot 无法完成绘制此图? [英] Why can't seaborn.pairplot finish drawing this plot?

查看:42
本文介绍了为什么 seaborn.pairplot 无法完成绘制此图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框 central

然后我想用 sns.pairplot(central)绘制列之间的成对关系.你能解释一下为什么这个过程永远运行吗?我在笔记本电脑和Colab上都尝试过,但是问题仍然存在.

Then I want to plot the pairwise relationships between the columns with sns.pairplot(central). Could you please explain why the process just runs forever? I tried on both my laptop and Colab, but the problem persists.

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 列的直方图也无法按预期工作.您可以通过定义箱号来克服此问题:

For reasons unknown to me, the histplot for column eigen_central has a problem determining a reasonable number of bins. The pairplot works with kde plots in the diagonal sns.pairplot(central, diag_kind="kde"), and the histplot for column eigen_central alone also does not work as expected. You can overcome this problem by defining the bin number:

sns.pairplot(central, diag_kws = {"bins": 10})

输出:

我将对所有可以提供一个原因的答案表示赞同,这些原因可以说明seaborn在定义垃圾箱时遇到的问题.这个问题是特定于 seaborn 的,因为 plt.hist(central.eigen) 按预期工作,但不是 sns.histplot(central.eigen).

I will upvote any answer that can provide a reason why seaborn has problems defining the bins. This problem is seaborn-specific as plt.hist(central.eigen) works as expected but not sns.histplot(central.eigen).

这篇关于为什么 seaborn.pairplot 无法完成绘制此图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆