Seaborn 警告消息

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

当我在接收参数 hue 的任何图中使用该参数时,我的笔记本会不断显示一条警告,该警告会影响我的可视化效果。以代码为例:

category_labels = ["Category A", "Category B"]
data = np.concatenate([np.random.randn(500), np.random.randn(500) + 3])
hue_labels = np.array([category_labels[0]] * 500 + [category_labels[1]] * 500)

sns.kdeplot(x=data, hue=hue_labels, common_norm=False, fill=True, palette="husl")

plt.show()

运行代码后,显示以下消息:

C:\Users\brian.oliveira\AppData\Local\anaconda3\Lib\site-packages\seaborn\_base.py:949: FutureWarning: When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group in a future version of pandas. Pass `(name,)` instead of `name` to silence this warning.

请问有人可以帮忙吗?

我尝试将不同的方法传递给“hue”,但没有成功。

python-3.x matplotlib seaborn data-analysis
1个回答
-1
投票

在 pandas 的未来版本中,当使用长度为 1 的列表(在您的情况下为 Hue_labels)进行分组时,您将需要传递长度为 1 的元组 您可以在定义hue_labels的代码下添加此代码以避免错误:

# to convert scalar values to tuples to prevent future warning
hue_labels = [(label,) for label in hue_labels]
© www.soinside.com 2019 - 2024. All rights reserved.