在seaborn联合情节中获得传奇 [英] Getting legend in seaborn jointplot

查看:39
本文介绍了在seaborn联合情节中获得传奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用 seaborn 联合图来可视化两个 numpy 数组之间的相关性很感兴趣.我喜欢 kind='hex' 参数给出的视觉区别,但我也想知道不同阴影对应的实际计数.有谁知道如何将这个传奇放在一边甚至是情节上?我尝试查看文档,但找不到.

I'm interested in using the seaborn joint plot for visualizing correlation between two numpy arrays. I like the visual distinction that the kind='hex' parameter gives, but I would also like to know the actual count that different shades correspond to. Does anyone know how to put this legend on the side or even on the plot? I tried looking at the documentation and couldn't find it.

谢谢!

推荐答案

更新以与新的 Seaborn 版本一起使用.

updated to work with new Seaborn ver.

您需要通过使用 add_axes 创建一个新轴来手动完成,然后将轴的名称传递给 plt.colorbar().

You need to do it manually by making a new axis with add_axes and then pass the name of the ax to plt.colorbar().

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

x = np.random.normal(0.0, 1.0, 1000)
y = np.random.normal(0.0, 1.0, 1000)
hexplot = sns.jointplot(x, y, kind="hex")
plt.subplots_adjust(left=0.2, right=0.8, top=0.8, bottom=0.2)  # shrink fig so cbar is visible
# make new ax object for the cbar
cbar_ax = hexplot.fig.add_axes([.85, .25, .05, .4])  # x, y, width, height
plt.colorbar(cax=cbar_ax)
plt.show()

来源:在我阅读开发人员说之后,我几乎放弃了 那个

工作/福利比率 [实施颜色条] 太高了"

"work/benefit ratio [to implement colorbars] is too high"

但后来我最终在在另一个问题中找到了这个解决方案.

but then I eventually found this solution in another issue.

这篇关于在seaborn联合情节中获得传奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆