Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib figure '.supxlabel' does not work

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.)
like image 765
danbuza Avatar asked Jan 26 '21 12:01

danbuza


People also ask

What is fig Add_axes Python?

add_axes plot inside plot matplotlib To create a figure object, use the figure() method. To define data points x and y. To plot a graph, use the plot() method of pyplot module. To add a plot inside an already generated plot, use the add_axes() method.


1 Answers

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).

like image 175
Zaccharie Ramzi Avatar answered Sep 20 '22 04:09

Zaccharie Ramzi