簡體   English   中英

Matplotlib 圖“.supxlabel”不起作用

[英]Matplotlib figure '.supxlabel' does not work

我正在嘗試為我的條件六邊形分箱 plot 設置圖形標簽,但是當我運行此代碼時,我得到 Attribute Error: 'Figure'object has no attribute 'supxlabel' 任何有關此問題的幫助將不勝感激。

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

使用此處給出的答案時,我遇到了同樣的問題。 事實證明,您需要兩件事:

  • Python 至少版本 3.7;
  • Matplotlib 至少版本 3.4 ( pip install --upgrade matplotlib )。

如果您在 3.7 下安裝 Python,則安裝matplotlib的 3.4 版將無法正常工作(至少在我的情況下沒有)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM