Seaborn 'pairplot' 函数以错误“'AxesSubplot' object has no attribute '_make_twin_axes'”结束

Seaborn 'pairplot' function ends with an error " 'AxesSubplot' object has no attribute '_make_twin_axes' "

我有 MacOsX、10.9.5、Mavericks。当前软件版本:

当我尝试调用 seaborn.pairplot 函数时,它以同样的错误结束。示例:

>>> import seaborn as sns
>>> iris = sns.load_dataset("iris")
>>> g = sns.pairplot(iris)

结果:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-a5463baed793> in <module>()
----> 1 g = sns.pairplot(iris)

/Library/Python/2.7/site-packages/seaborn/linearmodels.pyc in pairplot(data, hue, hue_order, palette, vars, x_vars, y_vars, kind, diag_kind, markers, size, aspect, dropna, plot_kws, diag_kws, grid_kws)
   1600     if grid.square_grid:
   1601         if diag_kind == "hist":
-> 1602             grid.map_diag(plt.hist, **diag_kws)
   1603         elif diag_kind == "kde":
   1604             diag_kws["legend"] = False

/Library/Python/2.7/site-packages/seaborn/axisgrid.pyc in map_diag(self, func, **kwargs)
   1303                                                  frameon=False)
   1304                 else:
-> 1305                     diag_ax = ax._make_twin_axes(sharex=ax, frameon=False)
   1306                 diag_ax.set_axis_off()
   1307                 diag_axes.append(diag_ax)

AttributeError: 'AxesSubplot' object has no attribute '_make_twin_axes'

我用easy_install重新安装了numpymatplotlib,重新安装了seaborn,还安装了seaborn的开发版。都没有帮助,我对每个配置集都有相同的错误。谷歌搜索这个问题也没有帮助,似乎我是唯一一个有这样问题的人。

也许私有成员 _make_twin_axes 已被弃用或更改。

更新:

  1. 降级到 matplotlib==1.4.2 没有帮助。
  2. 降级到 seaborn==0.4.0 没有帮助。
  3. 降级到 matplotlib==1.3.1 没有帮助。

降级后,我不确定错误在seabornmatplotlib,但现在我没有想法,可以做什么。

原因是 MacOS X 有一个内置的 Python。如果您键入(在 bashzsh 中)

which python

并接收

/usr/bin/python

那你可能用的是系统自带的Python.

下一步是获取订单,其中 Python 导入其包。我们运行python,然后

import sys
sys.path

通常是内置包的文件夹(不可升级)

'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python'

站在用户安装包的文件夹前

'/Library/Python/2.7/site-packages/'

所以你不能导入新的 matplotlib 除非你改变加载包的顺序或直接从安装它的文件夹导入你的 matplotlib(或 numpy,等等)。请注意,我无法卸载 1.1.1 matplotlib 版本。

另一个解决方案是安装两个版本的 python。官方推荐这种方式

我的解决方案有点硬核,这不是最好的解决方案,但希望从那以后没有出现任何问题。我从 Extras 中删除了文件夹 matplotlib,即旧的 1.1.1 版本,然后从 git 源安装了新版本。我只能推荐上述解决方案:)