我对使用 seaborn 的联合图来可视化两个numpy数组之间的相关性很感兴趣。我喜欢 kind='hex' 参数给出的视觉区别,但我也想知道不同阴影对应的实际计数。是否有人知道如何将此图例放在侧边栏甚至图中?我尝试查看文档但没有找到。
编辑:已更新以适用于新版的Seaborn。
您需要通过使用 add_axes
创建一个新轴,并将该轴的名称传递给 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()
来源:我曾经在阅读一位开发者说实现色条的
"工作/效益比太高了"
之后我几乎放弃了,但最终我在另一个问题中找到了这个解决方案。
plt.title
放置的位置确实不正确。 - seralouk
t1 = sns.jointplot(data=df, x="originalestimate_hours", y="working_hours_per_day_created_target", hue="status")
t1.ax_joint.legend_._visible=False
t1.fig.legend(bbox_to_anchor=(1, 1), loc=2)
AttributeError:'NoneType'对象没有属性'_visible'
。 - Rylan Schaeffer
plt.hexbin
,然后添加一个颜色条(我认为你所说的“图例”是指plt.colorbar
)。 - mwaskom