11

I'm trying to set figure labels for my conditioned hexagonal binning plot, but when I run this code I get the Attribute Error: 'Figure'object has no attribute 'supxlabel'. Any help with this problem would be appreciated.

zip_codes = [98188, 98105, 98108, 98126]

def hexbin_zips(ax, zipcode):
    kc_tax_zip = kc_tax_stripped.loc[kc_tax_stripped['ZipCode'] == zipcode]
    out = ax.hexbin(kc_tax_zip['SqFtTotLiving'], kc_tax_zip['TaxAssessedValue'], gridsize=30)
    return out

fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(12, 10), sharex='col', sharey='row')
axes = [ax1, ax2, ax3, ax4]

for n in range(4):
    hexbin_zips(axes[n], zip_codes[n])
    axes[n].set_title(str(zip_codes[n]))

fig.supxlabel('Total Living Space in Square Feet', fontsize=16.)
fig.supylabel('Tax-Assessed Value', fontsize=16.)
danbuza
  • 144
  • 1
  • 1
  • 10
  • 2
    This functionality has not yet been released. A workaround can be found in [this question](https://stackoverflow.com/questions/16150819/common-xlabel-ylabel-for-matplotlib-subplots) – DavidG Jan 26 '21 at 13:08

1 Answers1

16

I got into the same problem when using the answer given here. It turns out that you need 2 things:

  • Python at least version 3.7;
  • Matplotlib at least version 3.4 (pip install --upgrade matplotlib).

If you have Python under 3.7, the install of version 3.4 of matplotlib won't work (at least it didn't in my case).

Dharman
  • 30,962
  • 25
  • 85
  • 135
Zaccharie Ramzi
  • 2,106
  • 1
  • 18
  • 37