Search code examples
pythonpython-3.xseabornheatmapattributeerror

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


I'm trying to reproduce this answer but getting the following error:

AttributeError: 'GrouperView' object has no attribute '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'

Also, version is as below:

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

I checked some working around but couldn't solve the problem in the plot since there is no real string ax2,ax3 when I print :

Even I downgraded seaborn but didn't solve the problem based on this thread


Solution

  • As proposed in the 3.6 API changes, (and repeated in the 3.8 API changes), use Axes.sharey.

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

    Since an Axes can only sharey with one other Axes, I'm unaware of an alternative that lets ax1 share with both ax2 and ax3 in one step.