AttributeError:“GrouperView”对象没有属性“join”

问题描述 投票:0回答:1

我正在尝试重现此答案,但出现以下错误:

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'

此外,版本如下:

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

我检查了一些解决方法,但无法解决图中的问题,因为当我打印时没有真正的字符串

ax2,ax3

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

python seaborn heatmap attributeerror subplot
1个回答
0
投票

您的错误与seaborn无关。

您收到此错误是因为 matplotlib:

我尝试重现

你的 matplotlib 必须是

3.8+

当我将 matplotlib 升级到

3.8.1
时。我收到此错误:

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

我还在 matplotlib 3.6 中收到弃用警告

MatplotlibDeprecationWarning:join 函数在 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()

© www.soinside.com 2019 - 2024. All rights reserved.