我已经遵循了这个线程Seaborn Heatmap: Move colorbar on top of the plot中关于在图形上定位颜色条的答案
但是,我想将颜色栏缩小到默认值的50%。如果我读取colorbar函数的docstring,它建议我可以传递关键字参数“shrink”
这是我编写的代码(其中HM是seaborn热图):
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'
查看链接的帖子,我猜这是您尝试的步骤:
我得到了同样的错误:
因为
mpl_toolkits.axes_grid1.colorbar
没有收缩选项。它来自于评论中提出的plt.colorbar。切换到这个可能更好,因为mpl_toolkits.axes_grid1.colorbar module and its colorbar implementation are deprecated in favor of matplotlib.colorbar。所以应该这样做:相关问题 更多 >
编程相关推荐