Pycharm使用sns.distplot警告FutureWarning: `distplot` is a deprecated function and will be removed in a
程序员文章站
2022-07-14 23:00:12
...
前言
在pycharm下使用sns.distplot,出现警告,最终成功解决,如有错误,请纠正,万分感谢!
Pycharm 使用sns.distplot警告总结 && 解决方案
警告总结
引入包:
from matplotlib import pyplot as plt
import seaborn as sns
引入包之后,设置相应参数:
matplotlib.rc('figure', figsize = (14, 7))
matplotlib.rc('font', size = 14)
matplotlib.rc('axes', grid = False)
matplotlib.rc('axes', facecolor = 'white')
sns.distplot(data_com_X.time.apply(lambda x: int(x.year)+float(x.month/12.0)), bins=100, kde=False, rug=True)
plt.xlabel('time')
plt.ylabel('Number of short_comment')
点击运行,不仅不显示图片,还报警告:
C:\workSpace\PycharmProject\shixi\venv\lib\site-packages\seaborn\distributions.py:2551: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).
warnings.warn(msg, FutureWarning)
C:\workSpace\PycharmProject\shixi\venv\lib\site-packages\seaborn\distributions.py:2055: FutureWarning: The `axis` variable is no longer used and will be removed. Instead, assign variables directly to `x` or `y`.
warnings.warn(msg, FutureWarning)
解决方案
注:Pycharm显示图片,一定要用 plt.show()
!
加一句
可显示图片
但之前的警告还在!
警告中明确写明:
FutureWarning:
distplot
是已弃用的函数,将在以后的版本中删除。 请修改您的代码以使用“ displot”(具有类似灵活性的图形级函数)或“ histplot”(直方图的轴级函数)。
我 将distplot改为displot,即:
sns.displot(data_com_X.time.apply(lambda x: int(x.year)+float(x.month/12.0)), bins=100, kde=False, rug=True)
不再有警告,并且图片也有了变化!