【发布时间】:2021-05-14 02:28:44
【问题描述】:
我已按照此线程 Seaborn Heatmap: Move colorbar on top of the plot 上关于在图形上定位颜色条的答案。
但是我想将颜色条缩小到默认值的 50%。如果我阅读 colorbar 函数的文档字符串,它表明我可以传递关键字参数“shrink”。
这是我编写的代码(其中 HM 是海洋热图):
from mpl_toolkits.axes_grid1.colorbar import colorbar
HM_divider = make_axes_locatable(HM)
# define size and padding of axes for colorbar
cax = HM_divider.append_axes('right', size = '5%', pad = '25%')
# make colorbar for heatmap.
# Heatmap returns an axes obj but you need to get a mappable obj (get_children)
colorbar(HM.get_children()[0], cax = cax, orientation = 'vertical', shrink=0.5)
但是当我运行这个时,我得到一个 TypeError:TypeError: __init__() got an unexpected keyword argument 'shrink'
【问题讨论】:
-
this 会有所帮助。你运行的是什么版本的
matplotlib? -
嗨,杰。版本是 3.1.3
-
不要使用 make_axes_locatable 或为此。使用 ax.inset_axes 并且不要使用收缩参数,只需将插入轴设置为您想要的大小。
-
谢谢乔迪 - 了解该选项。但是我仍然很困惑为什么在这种情况下它不会采用收缩参数
-
如果你写
colorbar(),它来自哪个库?如果来自matplotlib.pyplot,请避免混淆,写成plt.colorbar()。
标签: python matplotlib seaborn