python - Matplotlib 图 '.supxlabel' 不起作用
问题描述
我正在尝试为我的条件六边形分箱图设置图形标签,但是当我运行此代码时,我得到 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
)。
如果您的 Python 版本低于 3.7,则安装 3.4 版matplotlib
将无法正常工作(至少在我的情况下没有)。
推荐阅读
- vue.js - 如何通过作用域插槽将表单输入元素传递给子组件
- c++ - 架构决策:返回 std::future 还是提供回调?
- abap - 如何从 ST03N 中提取“内存使用统计”?
- python - 我的海龟代码有什么问题?不能理解
- c# - 调试 Artifactory 中的 Nuget 包
- c# - 如何使用外键关系同时向两个表中插入新记录
- cloudera - Cloudera 管理服务的配置文件
- php - 返回 404 Wordpress 的所有页面和帖子(永久链接问题)
- amazon-web-services - 如何在 UI 中设计具有 4 个过滤器的 DynamoDB 索引
- python - 避免熊猫数据框的for循环来计算每个id python