python - 我怎样才能摆脱这些seaborn弃用警告并仍然得到完全相同的数字?

标签 python seaborn

当我运行此代码时:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

values = np.random.normal(loc=3.0,scale=1.0,size=50000)
df_FLIM = pd.DataFrame(values, columns=['Values'])
sns.set(font_scale=1.5, rc={'axes.facecolor':'pink','figure.facecolor':'white'})
f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})
sns.boxplot(df_FLIM["Values"], ax=ax_box, color='red')
sns.distplot(df_FLIM["Values"], ax=ax_hist, color='red')
ax_box.set(xlabel='')
plt.tight_layout()
plt.show()

我得到这个输出:

enter image description here

还有这些弃用警告:

C:\Users\lopez\AppData\Local\Continuum\lib\site-packages\seaborn_decorators.py:36:FutureWarning:将以下变量作为关键字参数传递:x。从版本 0.12 开始,唯一有效的位置参数将是 data,并且在没有显式关键字的情况下传递其他参数将导致错误或误解。 警告.警告( C:\Users\lopez\AppData\Local\Continuum\lib\site-packages\seaborn\distributions.py:2551: FutureWarning: distplot 是一个已弃用的函数,将在未来版本中删除。请调整您的代码以使用 displot (具有类似灵活性的图形级函数)或 histplot (直方图的轴级函数)。 warnings.warn(msg, FutureWarning)

我可以通过在 sns.boxplot 和“sns.displot”中使用“data=”而不是“sns.distplot”来消除这些警告,但随后我无法得到完全相同的数字。您能告诉我如何消除这些警告,同时获得完全相同的输出吗?

最佳答案

values = np.random.normal(loc=3.0,scale=1.0,size=50000)
df_FLIM = pd.DataFrame(values, columns=['Values'])
sns.set(font_scale=1.5, rc={'axes.facecolor':'pink','figure.facecolor':'white'})
f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, gridspec_kw={"height_ratios": (.15, .85)})
sns.boxplot(data=df_FLIM, x="Values", ax=ax_box, color='red')
sns.histplot(data=df_FLIM, x="Values", ax=ax_hist, color='red', kde=True, stat='density')
ax_box.set(xlabel='')
plt.tight_layout()
plt.show()

enter image description here

关于python - 我怎样才能摆脱这些seaborn弃用警告并仍然得到完全相同的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65597911/

相关文章:

python - 如何检查列是否包含列表

python - 在 numpy 中按值拆分数组

pandas - 如何有条件地在seaborn条形图中显示数据帧的不同列值?

python - ValueError : could not convert string to float - sns. tsplot,时间 - 使用字符串来标记 x 轴

python - 无法在 Ubuntu 16.04 上使用 pip 安装 uwsgi

python - 在python列表中将数字转换为成绩

python - 如何在 Pandas 的时间序列图上绘制垂直线?

python - seaborn FacetGrid : How to leave proper space on top for suptitle

python - Python 的颜色 (seaborn) : colors without adding to DataFrame

python - 如何使用Python按时关闭浏览器(ChromeDriver)