我正在为一些具有数百万个数据点的数据制作二维直方图。 matplotlib.hist2d(x,y,bins,norm=LogNorm())
运行良好并在大约 5 秒内生成绘图,但我喜欢 seaborn.jointplot()< 的边际直方图
。如何使用随附的 matplotlib.hist2d()
图中点的对数密度为 seaborn.jointplot()
中的点着色?使用 KDE 花费的时间太长(大约一分钟后我就放弃了),而且我有很多图形要创建。所以“获得”颜色的时间是一个因素。或者,如何将边际直方图添加到 matplotlib.hist2d()
?
plt.hist2d(x,y,100,norm=LogNorm(),cmap='jet')
sns.jointplot(x=x, y=y)
最佳答案
在 seaborn
中可能还有另一种直接获取颜色图的方法。我还没有找到。这是一个 hacky 示例解决方案,用于使用一些随机数据完成工作。至于你的第二个问题,我建议发布一个新问题。
诀窍是首先使用 seaborn 创建一个 jointplot
,然后隐藏 2d 散点图并使用 plt.hist2d
重新绘制它
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
# some random data
x = np.random.normal(size=100000)
y = x * 3.5 + np.random.normal(size=100000)
ax1 = sns.jointplot(x=x, y=y)
ax1.ax_joint.cla()
plt.sca(ax1.ax_joint)
plt.hist2d(x, y, bins=(100, 100), cmap=cm.jet);
关于python - seaborn jointplot 按密度颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53964485/