python-3.x AttributeError:'GrouperView'对象没有属性'join'

balp4ylt  于 7个月前  发布在  Python
关注(0)|答案(2)|浏览(316)

我试图重现这个answer,但得到以下错误:
AttributeError:'GrouperView'对象没有属性'join'

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[283], line 7
      4 flights = flights.pivot("month", "year", "passengers")
      5 f,(ax1,ax2,ax3, axcb) = plt.subplots(1,4, 
      6             gridspec_kw={'width_ratios':[1,1,1,0.08]})
----> 7 ax1.get_shared_y_axes().join(ax2,ax3)
      8 g1 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax1)
      9 g1.set_ylabel('')

AttributeError: 'GrouperView' object has no attribute 'join'

字符串
seaborn版本如下:

print(sns.__version__) #0.13.0
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__) #matplotlib: 3.8.1)


我检查了一些工作,但无法解决图中的问题,因为在打印时没有真实的字符串ax2,ax3

即使我降级了seaborn,但没有解决基于此thread的问题

dgenwo3n

dgenwo3n1#

如3.6 API更改中所建议的(并在3.8 API更改中重复),使用Axes.sharey

ax1.sharey(ax2)
ax2.sharey(ax3)

字符串
由于Axes只能与另一个Axes共享sharey,因此我不知道有一种替代方法可以让ax1在一个步骤中与ax2ax3共享。

0yycz8jy

0yycz8jy2#

解决方案:请将matplotlib降级到3.7或3.6

你的错误与海运无关,
由于matplotlib,您会收到此错误:
当我将matplotlib升级到3.8.1时,我收到这个错误:

AttributeError: 'GrouperView' object has no attribute 'join'

字符串
此外,我在matplotlib 3.6中收到了弃用警告

MatplotlibDeprecationWarning:联接函数在Matplotlib 3.6中已被弃用,将在两个次要版本之后删除。

我可以在matplotlib 3.6和3.7中复制图形
此处为代码:

import seaborn  as sns
import matplotlib.pyplot as plt
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
f,(ax1,ax2,ax3, axcb) = plt.subplots(1,4, 
            gridspec_kw={'width_ratios':[1,1,1,0.08]})
ax1.get_shared_y_axes().join(ax2,ax3)
g1 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax1)
g1.set_ylabel('')
g1.set_xlabel('')
g2 = sns.heatmap(flights,cmap="YlGnBu",cbar=False,ax=ax2)
g2.set_ylabel('')
g2.set_xlabel('')
g2.set_yticks([])
g3 = sns.heatmap(flights,cmap="YlGnBu",ax=ax3, cbar_ax=axcb)
g3.set_ylabel('')
g3.set_xlabel('')
g3.set_yticks([])

# may be needed to rotate the ticklabels correctly:
for ax in [g1,g2,g3]:
    tl = ax.get_xticklabels()
    ax.set_xticklabels(tl, rotation=90)
    tly = ax.get_yticklabels()
    ax.set_yticklabels(tly, rotation=0)

plt.show()


的数据

相关问题