【问题标题】:How can I get rid of these seaborn deprecation warning and still get the exact same figure?我怎样才能摆脱这些 seaborn 弃用警告并仍然获得完全相同的数字?
【发布时间】:2021-04-12 07:49:14
【问题描述】:

当我运行这段代码时:

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()

我得到这个输出:

还有这些弃用警告:

C:\Users\lopez\AppData\Local\Continuum\lib\site-packages\seaborn_decorators.py:36:FutureWarning:将以下变量作为关键字 arg 传递:x。从版本 0.12 开始,唯一有效的位置参数将是 data,并且在没有显式关键字的情况下传递其他参数将导致错误或误解。 警告.warn( 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”来消除这些警告,但是我无法得到完全相同的数字。你能告诉我如何摆脱这些警告,同时获得完全相同的输出吗?

【问题讨论】:

标签: python seaborn


【解决方案1】:
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()

【讨论】:

    【解决方案2】:

    与您要导入的所有库一起尝试:

    导入警告 warnings.filterwarnings("忽略")

    【讨论】:

      猜你喜欢
      • 2011-03-12
      • 2021-01-27
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-28
      • 2023-01-29
      相关资源
      最近更新 更多