我搜索了S/O,但找不到答案.

当我试图用seaborn绘制分布图时,我得到了一个future 警告.我想知道这里有什么问题.

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
% matplotlib inline
from sklearn import datasets

iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['class'] = iris.target
df['species'] = df['class'].map({idx:s for idx, s in enumerate(iris.target_names)})


fig, ((ax1,ax2),(ax3,ax4))= plt.subplots(2,2, figsize =(13,9))
sns.distplot(a = df.iloc[:,0], ax=ax1)
sns.distplot(a = df.iloc[:,1], ax=ax2)
sns.distplot(a = df.iloc[:,2], ax=ax3)
sns.distplot(a = df.iloc[:,3], ax=ax4)
plt.show()

以下是警告:

C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713:
FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; 
use `arr[tuple(seq)]` instead of `arr[seq]`. 
In the future this will be interpreted as an array index, `arr[np.array(seq)]`,
which will result either in an error or a different result.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

有什么帮助吗?您可以运行上面的代码.你会得到警告的.

大Pandas :0.23.4只,海生:0.9.0只,matplotlib:2.2.3只,scipy:1.1.0只,numpy:1.15.0'

推荐答案

更全面的追踪会更好.我猜seaborn.distplot是用scipy.stats来计算的.错误发生在

def _compute_qth_percentile(sorted, per, interpolation_method, axis):
    ....
    indexer = [slice(None)] * sorted.ndim
    ...
    indexer[axis] = slice(i, i + 2)
    ...
    return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

所以在最后一行中,列表indexer用于切片sorted.

In [81]: x = np.arange(12).reshape(3,4)
In [83]: indexer = [slice(None), slice(None,2)]
In [84]: x[indexer]
/usr/local/bin/ipython3:1: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  #!/usr/bin/python3
Out[84]: 
array([[0, 1],
       [4, 5],
       [8, 9]])
In [85]: x[tuple(indexer)]
Out[85]: 
array([[0, 1],
       [4, 5],
       [8, 9]])

使用切片列表是可行的,但计划是在future 贬值.涉及多个维度的索引应该是元组.在上下文中使用列表是一种正在逐步淘汰的旧样式.

所以scipy名开发者需要解决这个问题.这不是最终用户应该处理的事情.但现在,不要担心futurewarning.它不会影响计算或绘图.有一种方法可以压制future 的警告,但我现在还不知道.

FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated use `arr[tuple(seq)]` instead of `arr[seq]`

Python-3.x相关问答推荐

Django 5.0.2和django_rest_framework

在Python中从mySQL获取多行

CONNEXION.EXCEPTIONS.ResolverError:运行pyz文件时未命名模块

如何通过Pandas为不同的列集垂直设置列数据?

Django 模型类方法使用错误的 `self`

你能骗PIP 让它相信包已经安装了吗

使用 Python 在特定组的列中设置上限

在 pytest 中,如何测试 sys.exit('some error message')?

有没有办法使用重采样矢量化添加缺失的月份?

通过附加/包含多个列表来创建 nDimensional 列表

Python:如何在三个列表中找到共同值

pysftp vs. Paramiko

通过多个键对字典列表进行分组和聚合

如何正确创建自定义文本编解码器?

谁能给我一个 Python 3 中标准输入和标准输出的快速教程?

如何使用已打开并使用登录凭据登录的浏览器

将字符串拆分为最大长度 X 的片段 - 仅在空格处拆分

python asyncio add_done_callback 与 async def

使用 Python 3 读取 CSV 文件

print(... sep='', '\t' ) 是什么意思?